AtCoder Beginner Contest 336
AtCoder Beginner Contest 336
57 秒切 A,75 秒切 B。
然后 C 就卡了,没想到五进制,二分答案加数位 DP 判断过了。用了半个小时。
DE 读完题,发现 D 可做。小推了一下发现可以维护线段树。
很快写完过了样例。
第一发罚时,
第二发罚时,把那个“金字塔”写成了
第三发,第四发,第五发,第六发,第七发都是有四个或三个点没过。
第八发过了。原因竟是线段树 query 没 pushdown。
D 是在结束前三分钟切的。E 当然就没时间了。
C - Even Digits
想复杂了。
Description
A non-negative integer
- All digits in the decimal notation of
are even numbers ( , , , , and ).
For example,
You are given an integer
Solution1 二分 + 数位 DP
二分
发现这个形式很像数位 DP。于是套路的将
具体的是代码。
Solution2 五进制
我们可以将
注意题目中
时间复杂度
D - Pyramid
仍然想复杂了。
Description
For a positive integer
You are given a sequence
Find the maximum size of a Pyramid Sequence that can be obtained by repeatedly choosing and performing one of the following operations on
- Choose one term of the sequence and decrease its value by
. - Remove the first or last term.
It can be proved that the constraints of the problem guarantee that at least one Pyramid Sequence can be obtained by repeating the operations.
Solution1 二分 + 线段树
发现答案是有单调性的(如果
接下来的问题就是在
我们令
所以在二分 check 的时候可以计算出这个
但是对于每个区间
可以发现,在这个变化过程中。
具体地,当从区间
- 对于所有
, ; - 对于所有
, 。
然后发现
时间复杂度
具体看代码。
Solution2 递推
令
令
有递推:
; 。
那么答案为
原因显然。时间复杂度
代码。
E - Digit Sum Divisible
跟 @xz001 学会了记忆化搜索的数位 DP。
Description
The digit sum of a positive integer
A positive integer
You are given a positive integer
Solution
数位 DP。
可以发现数位和最大为
设状态
:搜到了第 位(倒着枚举,也就是指 到最高位都填完了)。 :是否 前面的位(包括 )都填满了。这里的填满指填的与原数 相同。例如 就是在 时第五到最高位的填满。 : 前面的位从左往右拼成的十进制数模数位和为 。例如 的第四到最后一位组成的十进制数为 。 : 前面的数位和为 。例如 的第四到最后一位的数位和为 。
转移是这样的:
。表示枚举第 位填的数为 。那么因为前面存在某一位没填满,那么后面的位 都是可以填的。因此 的范围为 。 ,其中 表示给定的 的第 位, 表示 是否等于 (真为 ,假为 )。表示枚举的第 位为 。那么因为前面每一位都填满了,那么这一位肯定不能超过 原来的这一位,所以枚举到 。
令
边界显然
代码。
F - Rotation Puzzle
水题。赛时没看。
Description
Problem Statement
There is a grid with
Specifically, for
Below, let
Determine if it is possible to reach a state where, for all pairs of integers
the cell
If it is possible, print the minimum number of operations required.
If it is impossible in
Operation: Choose a rectangle of size
from the grid and rotate it degrees.
More precisely, choose integersand ,
and for all pairs of integerssatisfying and ,
simultaneously replace the integer written in cellwith the number written in cell .
Note that it is only necessary for the integers written in the cells to satisfy the condition; the orientation in which they are written does not matter.
- If
, then - All input values are integers.
Solution
可以发现,对于每种状态,它会有
但是发现这个旋转
复杂度约为
思路不难,实现略需技巧。代码。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!