We will hold AtCoder Regular Contest 202 (Div. 1).
- Contest URL: https://atcoder.jp/contests/arc202
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250720T2100&p1=248
- Duration: 150 minutes
- Number of Tasks: 4
- Writer: Nyaan
- Tester: maspy
- Rated range: 1600 ~ 2999
The point values will be 700-800-900-1000.
Please note that starting from this contest, AtCoder Rules against Generative AI will also apply to ARC Div.1.
We are looking forward to your participation!








If you keep getting WA at problem A, maybe you can try this case
n = 4, and a[4] = {2, 1, 2, 2}
the answer should be 1.
https://codeshare.io/5OKppr
can you help me with any sample TC, its giving WA for 14 TCs.
TIA
I checked some handmade testcases and
n=5 and a[5] = {1,1,1,1,1}
fails (it should be 2, not 3)
thank you
Hi, I just coded (code) the simulation described in the official editorial for problem A. But as it is alreadt mentioned, it's too slow and getting TLE. Here is the text from the Editorial:
The above simulation is slow if performed naively, but can be computed in O(NlogN) by appropriately using std::set. Furthermore, with a bit more consideration, when there is a pattern like Ai>Ai+1=Ai+2=⋯=Aj−1<Aj, it can be proved that it is optimal to align the middle part to either Ai or Aj using merge operations and insertion operations, so it can also be solved in O(N) using a stack.Honestly, I am not undersating any part of implementation or proof of this above statement. I understood that I need to reach min(left value, right value) from current value, but I am not able to calculate the cost of that in O(1) or O(logn).
Could you please help me by giving some hint regarding this?
Thanks to Dominater069, I figured out that part.
tasks were somewhat standard today. Particularly, A and D.
A, to me, was just straightforward implementation. D was trivial extension of 1967E1 - Again Counting Arrays (Easy Version).
B was nice! Thanks for the ratings anyways.
Hi, could you please reply the link of your implementation of A?
Submission
This is a brilliant implementation. Learned a lot from this. Thanks.
Can someone help with any hints/intuition for C?
I wrote my during-contest solution into words in Simplified Chinese, you can ask AI to translate into any language: https://www.luogu.com/article/o9ckfy17
I was expecting worse from the problem D with its 15s TL, but my solution ($$$T^{3/2}$$$ or something) works in ~800ms.
Also, I had a revelation that counting 1-d walks with not moving sometimes can be computed from 1-d walks with always moving via a simple convolution (and the always-moving part here was doable in like $$$T^2/H$$$).
Anyway, thanks for the contest!
In Editorial for C, I am assuming we calculate each $$$F_i$$$ as follows:
$$$F_i = \frac{R_i}{ \prod_{d \mid i, d \neq i} F_d}$$$ and base case $$$F_1 = 1$$$
So how do we prove that $$$F_1,F_2...F_n$$$ are all integers and are pairwise coprime?
In this context it seems you don't need to. The conclusion holds regardless of whether $$$F_i$$$'s are integers and coprime or not. You can calculate them in the sense of reducing modulo $$$998244353$$$.
I'll provide a proof of the integrality of $$$F_i$$$. Introducing the cyclotomic polynomials. They have the property
The integrality of $$$F_i$$$ follows from the integrality of the coefficients of cyclotomic polynomials.
Loved the problems! B is very nice!
My solution to C is $$$O(\sum_{i=1}^Md^2(i))=O(M \log M \sqrt M)$$$,where $$$d(i)$$$ is the number of factors of $$$i$$$, but it still pass.(The judge in atcoder is really fast.)
My submission
For each pair of factors $$$a, b$$$, the number of $$$i$$$-s is $$$M / LCM(a,b) = \frac{M GCD(a,b)}{ab}$$$. The total sum is at most $$$\sum_g \sum_{a=1}^{M/g} \sum_{b=1}^{M/g} \frac{M}{gab} \sim \sum_g \frac{M}{g} \log^2(M/g) \sim M \log^3(M)$$$. That's a rough bound that doesn't skip non-coprime $$$a,b$$$ — maybe that even cuts down a log.
Calculating your expression, it's only 6.1e7 for the given 2e5, increasing to only 1.8e8 for 5e5 and it's 2.6e7 for 1e5. That corresponds to asymptotic rise around $$$M \log^{2.5} M$$$ (constant only fitted on those 3 data points, not computed).
Thank you.
Can somebody explain the discussion of situation $$$W$$$ is even in problem B? I can only find out the conclusion when $$$W$$$ is odd.
In each row, you can choose how the column changes in the next move, from 4 options: "always subtract 1", "always add 1", "add for even columns, subtract for odd" or vice versa. Let's denote the counts of columns with the first 2 options by $$$n_{-}$$$ and $$$n_{+}$$$.
Since $$$H$$$ is odd but $$$W$$$ even, one "cycle" of $$$H$$$ moves returns you to the starting row but a column with different parity. This cycle shifted your column by $$$n_{+} - n_{-}$$$ when visiting rows with the first 2 options assigned, and by something when visiting rows with the other 2 options. You don't need to know that something because in the next cycle of $$$H$$$ moves, the parities of the columns you visit in each row will be flipped; this doesn't affect the $$$n_{+}$$$ and $$$n_{-}$$$ rows, but for the remaining rows, you know they'll shift your position in the opposite direction from the previous cycle, so it cancels out and it's as if they didn't change your position.
In $$$2H$$$ moves, your position changes by $$$2(n_{+} - n_{-})$$$ and just like in the case of odd $$$W$$$, this needs to be non-zero and coprime with $$$W/2$$$.
I ignored the last two options of the column change.
Now I realized it. Thank you! :)
Different explanation of C, though the point should be the same: we start by calculating just the last answer since the resulting algorithm can be implemented in an online queries way.
Using the standard subtraction formula for GCD, we derive $$$GCD(10^a-1, 10^b-1) = 10^{GCD(a,b)}-1$$$. This generalises to an arbitrary number of elements.
We know $$$max(S) = \sum_{T \subset S, T \neq \emptyset} (-1)^{|S|+1} min(T)$$$, e.g. max(a,b,c,d) = a+b+c+d-min(a,b)-min(a,c)-...-min(c,d)+min(b,c,d)+min(a,c,d)+min(a,b,d)+min(a,b,c)-min(a,b,c,d). Simple proof: the $$$k$$$-th largest element will appear in $$$2^{k-1}$$$ sets, their parities cancel out iff $$$k \gt 1$$$. Since the exponents of all primes in LCM are max over those in $$$A_i$$$ and exponents of all primes in GCD are min, the same rule works if max/min are replaced with LCM/GCD and add/sub with mul/div.
Among the exponents $$$A_i$$$, we need to calculate the (count of odd-sized subsets — count of even-sized subsets) "count-dif" with each possible GCD; then the answer is $$$\prod_i (10^i-1)^{cnt_{i,odd} - cnt_{i,even}}$$$. First we calculate the count of exponents divisible by each $$$i$$$. If there are none, $$$i$$$ can be ignored. Otherwise the count-dif of subsets whose GCD is divisible by $$$i$$$ is exactly 1 because it'd be 0 if we included the empty subset (GCD = 0) and that has even size. From that, we need to subtract the count-dif of all proper multiples of $$$i$$$ to get count-dif of subsets whose GCD is equal to $$$i$$$. This can be calculated in the decreasing order of $$$i$$$, in $$$O(M \log M)$$$.
How do we generalise this to online queries? The key is that the exact count of exponents divisible by $$$i$$$ doesn't matter, the only thing that affects the answer is if it's non-zero. When a new $$$A_i$$$ comes in, we update that for $$$A_i$$$ and recursively for all its minimal divisors (from $$$a$$$ to $$$a$$$ / prime), immediately turning back in recursion if some $$$a$$$ already occurred before. This ensures that each divisor is only processed once so recursion tries to branch $$$O(M \log M)$$$ times.
The second thing is that going from count-dif for GCD divisible by $$$i$$$ to count-dif for GCD equal to $$$i$$$ is a linear operation, so each operation "$$$i$$$ appeared for the first time as a divisor" just multiplies the answer by some $$$c_i$$$. These $$$c_i$$$ can be calculated in the exact same way we calculated count-dif, just in increasing order: $$$c_i = (10^i-1) / \prod_{d | i} c_d$$$.