We will hold AtCoder Beginner Contest 419.
- Contest URL: https://atcoder.jp/contests/abc419
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250816T2100&p1=248
- Duration: 100 minutes
- Writer: cn449, toam, chokudai
- Tester: Nyaan, kyopro_friends
- Rated range: ~ 1999
- The point values: 100-200-300-400-475-550-600
We are looking forward to your participation!








I like 100-200-300-425-475.....
First comment after CF became alive!
Good contest, but big gap between F and G. Also, problem F is bad. It requires no thinking but AC automaton, a advanced data structure used to solve problems about strings.
You actually don't need AC automation, constraints lets you just use for loops.
https://atcoder.jp/contests/abc419/submissions/68552444
I used inclusion-exclusion principle + DP of DP.
https://atcoder.jp/contests/abc419/submissions/68560930
someone explain E in the easiest possible way please :sob:
It's DP. first of all, a[ i ], a[ i + L ], a[ i + 2 * L ],... should have the same reminder divided by M. Now for i to L and for j to M, b[ i ] [ j ] is the total number of operations needed to make all a[ i ], a[ i + L ], a[ i + 2 * L ],... have a reminder of j divided by M. Now , for i to L and for j to M and for k to M, update dp [ i ] [ ( j + k ) % M ] with dp [ i -1 ] [ k ] + b [ i ][ j ]. The answer would be dp [ L — 1 ] [ 0 ]. p.s: dp [ i ] [ j ] means the minimum number of operations needed to make the sum of first i+1 elements of the array has a reminder of j, divided by M. here is my submission: https://atcoder.jp/contests/abc419/submissions/68572396
C>=D. And D good but esay.
I wonder who that person is who spent ages trying to make an inclusion-exclusion solution work for F, only to fail... couldn't be me, right?
I coded it out, see it here: https://atcoder.jp/contests/abc419/submissions/68560930
Hi, I think the test data for G is weak, and the sample solution is slightly wrong. For the input
the answer should be
0 5 0 0 0 0, but the sample solution gives0 1 0 0 0 0(and passes).Thank you!
(Also I tested some of the top submissions, and they correctly output
0 5 0 0 0 0, so I don't think that this will change the rankings significantly)Thank you for your report!
I’ve fixed the sample solution code —— apologies for the mistake.
The testcase outputs were generated with a correct solution, so the contest results are unaffected.
(I slipped up while trimming down the editorial code to keep it concise...)
Thanks! I also think the test data is weak, because the broken sample solution managed to AC. You would need a test case like the one I gave to prevent solutions like this from passing.
https://atcoder.jp/contests/abc419/submissions/68579462 (my CPP solution, but should be using a multiset rather than a set)
https://atcoder.jp/contests/abc419/submissions/68509954 (your CPP solution)
Can someone please explain why in problem C, median of row and column values does not work? I guessed that mid point might work after median approach failed, but I cannot understand why it fails.
Let $$$x$$$ be the average of all the points' coordinates along a certain direction, then $$$x$$$ minimizes the sum of the squared differences, i.e. $$$x = minarg_{a \in \mathbb{Z}} \sum{(a - x_i)^2}$$$, which is not what we want.
Let $$$x$$$ be the median of all the points' coordinates along a certain direction, then $$$x$$$ minimizes the sum of the absolute value of the differences, i.e. $$$x = minarg_{a \in \mathbb{Z}} \sum{|a - x_i|}$$$, which is not what we want.
What we want here is to minimize the maximum distance, therefore $$$x$$$ should be the average between the 2 extremal values in that direction.
Got it. Median works for the case of summations, which is not what we want here. Thanks!!
From C to E, the topics are [binary search + math], [segment covering trick], [dp + math + periodicity].
To my surprise, problem F is dp based on Aho-Corasick automaton !! This is crazy :D
Binary search in C? C is just like
I didn't realize that problem C can be solved based on pure math. Thank you so much for sharing your solution, which I think is quite neat and clear, and has linear complexity.
hey how to do E?
Here is my solution.
The problem requests that a[1]+a[2]+...+a[L] = a[2]+a[3]+...+a[L+1] (mod M), and then we can get that a[1] = a[L+1] (mod M). Applying this to all the other contiguous subarrays, and we can find that a[x] = a[x+L] (mod M) must hold. This observation is quite important, and this is where periodicity comes from.
Now, consider a[1]=a[1+L]=a[1+2L]=... (mod M), and we can compute the minimum number of operations to make all of them equal to some x, where x =0,1,2,...,M-1, based on some math. The total complexity is O(L*N*M), which is fast enough. We use cost[i][r] to denote the minimum number of operations that we need to make a[i]=a[i+L]=a[i+2L]=...=r (mod M)
Next, we use dp[i][r], defined as follows:
The transition is as follow: dp[i][r] = min(dp[i][r], dp[i — 1][r1] + cost[i][r2]) and we can brute-force r1 and r2, where both r1 and r2 take values from 0,1,2,...,M-1, and r = (r1+r2) % M. The complexity of this step is O(L*M*M), which is fast as well.
yeah got that thanks
How to E in $$$O(NM)$$$ ?
It was my first time being able to solve D, but I still only made it to the top 4000. Maybe D was easier than in previous contests, and even easier than C this time.
yeah