We will hold AtCoder Beginner Contest 420.
- Contest URL: https://atcoder.jp/contests/abc420
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250824T2100&p1=248
- Duration: 100 minutes
- Writer: sounansya, physics0523
- Tester: MMNMM, sheyasutaka
- Rated range: ~ 1999
- The point values: 100-200-300-400-450-550-575
We are looking forward to your participation!








it's on Sunday!
Waited for a few minutes after 12:00 UTC for the tasks to appear, thinking the site hanged. Turns out its on sunday...
Some ABCs would be on Sundays later on. Interesting change, ruins my schedule :( but still gonna participate anyways
G too easy
Yes!It's a easy math problem
Today's E is very easy.
G <<< F !!
Rubbish round.
May I kindly ask who invents the problem G and places it at G?????
Also I missed $$$n \cdot m \le 5 \cdot 10^6$$$ in F and obtain two TLEs because I wrote $$$O(\min^2(n,m)\max(n,m))$$$ with 100 percentage confidence.
How you counted pairs ?? Or you didn't find any need to count them at all. Editorial uses Cartesian Tree but that is still unknown me to me.
By Pairs I mean this :-
// 1 <= X <= L. // 1 <= Y <= R. // 2 <= (X + Y) <= Sum.
Maybe this part is the reason for my TLE. Can you please help ??
My function looked like this :-
It's funnier because editorial solution for F uses cartesian tree (which isn't necessary) and that's still somehow meant to be easier than G
G was an easy brute force Diophantine Equation. By the way how you approached problem F after utilising NSEE and PSE ??
My solution is similar to yours. But I get an AC after 5 TLEs.
code
where the solution gets uploaded?
Here: https://atcoder.jp/contests/abc420/editorial
After solving F, my rank only increased by ~100 cuz of G lol
bruh round
Lot of cheating in today round , don't what the point on cheating in the mock exams .
Exams?
Can you please help me like what I'm doing in the 4th problem I was using dynamic programming as the 500 I was just doing all the possible recursive calls but the issue was how I can keep the track of visited array because if I mark visited after going to the next Possible way I can also come to this path again , So is dp work in this problem or something else , i think about bfs but i didn't get approach using bfs , i have 50 minutes to think but i was not able to get victory over 4th problem again
Recursion won't work. DP not required. You need to start BFS from the s node/cell.
Treat this as a shortest path problem.
A true beginner contest after long time.
1 WA in G, WHYYY???? T_T
https://atcoder.jp/contests/abc420/submissions/68785856
when x=0, the answer is -1 and 0
Swap D and G
Problem F is so shity. It involves too much discussion between different situations. It's really hard to implement all the details correctly in short time.
PS: It is able to pass using algorithms with complexity O(n*m*min(n,m)), which can be as much as 1e10 operations.
Well, D was a good exercise in basic BFS implementation, I guess. But the real "challenge" was figuring out why F was seemingly 10x harder than G (which had 10x the passes!). The difficulty allocation this time was truly baffling!
In problem G, 4x-1 = (2m+2n+1)(2m-2n-1). But how people who solved it, come up with this idea? Or there was another approach?
Actually I upsolved it in a different way.
if $$$\sqrt{n^2 + n + X}$$$ is an integer, then it must be a perfect square. So for some integer $$$k$$$,
Then I just brute force every value of $$$k \in [-10^{8}, 10^{8}]$$$ and store every integer value of $$$n$$$ I encounter in this process.
AC Link: https://atcoder.jp/contests/abc420/submissions/68790074
I used the same method, actually $$$k\in [-2\times 10^7,2\times 10^7]$$$ is fine, approximately, k is $$$sqrt(x)$$$
Super bad problem G, because G can be solved by chatGPT-5 in 2 minutes and 19 seconds. That's the reason so many people solved G.
Testers in ABC should enforce that at least problem F and G (or at least G) cannot be solved by GPT.
It's nearly impossible. GPT-5 is really powerful yet. It can solve almost all the problems in previous ABCs.
By the way, why your GPT needs 2 minutes to solve G? I suppose that GPT can solve this problem really fast, somehow in 10 seconds or less.
AtCoder rules says "The use of generative AI is generally prohibited during ongoing ABC and ARC." So if someone uses GPT, that’s on them, that's against the rules.
You said chat gpt needed 2 minutes 19 seconds for G, but that’s just skill issue. With my prompt it solves G in under a minute.
If you want a non-GPT-able contest then make everything 2500-rated and watch only 100 people solve it. Otherwise stop spamming every contest blog. BEGINNER CONTESTS ARE FOREVER CHATGPT-ABLE. get used to it.
stop the spam, thank you!
[this is a reply to everyone complaining, not only to you.]
D — Toggle Maze.
Why BFS does work? See input below. Editorial Solution is 14 but correct is 16 : (4,2)->(3,2)->(2,2)->(3,2)->(4,2)->(5,2)->(6,2)->(6,3)->(6,4)->(6,5)->(5,5)->(5,6)->(4,6)->(3,6)->(3,5)->(3,4)->(4,4)
You miss the (4,2)->(4,1)->(5,1)->(6,1)->(6,2)->(6,3) route
excuse me , who solve first problem in 16 freaking seconds
That's 26 seconds, but A is super ez it's not that hard to come up with a solution. Plus: he use Python
As my solution to F was different from editorial:
Assuming $$$N \leq M$$$, (if not, rotate), $$$N*M \leq 5e6 \implies N \leq sqrt(5e6) \lt 2237$$$
So we can bruteforce the upper row $$$r_1$$$ of the rectangle, and the rectangle height $$$h$$$ from $$$1$$$ to $$$\min(K,N-r_1)$$$ (0-indexed). As a result, we also have an upperbound of the maximum width $$$w = \lfloor \frac{K}{h} \rfloor$$$
For the current pair ($$$r_1$$$, $$$h$$$), call a column $$$c$$$ valid if all cells from $$$\text{grid}[r_1\ldots r_1+h-1][c]$$$ are free.
Now, it's a 1D problem. We have $$$M$$$ binary integers (valid column = $$$1$$$). To count all valid rectangles, we can group all contiguous $$$1\text{s}$$$ together. To solve naively in $$$\mathcal{O}(N^2*M)$$$:
For each group of $$$1\text{s}$$$, let the current group have length $$$X$$$
Case 1: $$$X \leq w$$$: Contributes $$$X*(X+1)/2$$$ to the answer
Case 2: $$$X \gt w$$$: Contributes $$$w*(w+1)/2 + (X-w)*w$$$ to the answer
This solution is too slow but we can speed it up.
Precompute for each cell $$$(i,j)$$$, the smallest $$$k$$$ such that $$$i \leq k$$$ and $$$\text{grid}[k][j]$$$ is obstacle (or $$$N$$$ if none exists).
Bruteforce from largest $$$h$$$ to lowest $$$h$$$, and add all columns that are valid for the first time at current $$$h$$$
When adding a column, use a DSU to maintain the current state of the group lengths and use three fenwicks to maintain the answer for each group length. The first fenwick for case 1, the other two to handle case 2. Make sure to start from $$$h = N-r_1$$$ but only add to answer for $$$h \leq k$$$
Final Complexity: $$$\mathcal{O}(N*(N+M)logM)$$$
Submission
Thank you for sharing your solution, where the DSU part has really inspired me a lot. My solution is almost the same as yours, but instead of using segment tree, I use dp[x][y] to simplify the calculation.
Here dp[x][y] means that for a grid consisting of only '.', with x rows and y columns, the number of valid sub-rectangles which start from the first row is dp[x][y]. For instance, dp[3][1] = 3, dp[2][2] = 6. This dp can be calculated based on the idea like two-dimension prefix sum.
It was a great contest, I enjoyed it.
If you solved https://cses.fi/problemset/task/1148 in a fast enough way, you can just paste, change some sizes, sum all rectangles $$$i\cdot j \lt = k$$$ and submit to problem F.