We will hold OMRON Corporation Programming Contest 2025 (AtCoder Beginner Contest 397).
- Contest URL: https://atcoder.jp/contests/abc397
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250315T2100&p1=248
- Duration: 100 minutes
- Writer: sotanishy, MtSaka, sounansya, kyopro_friends, blackyuki
- Tester: math957963, cn449
- Rated range: ~ 1999
- The point values: 100-250-350-425-475-550-625
We are looking forward to your participation!








I am sure we will have fun in this round ! GL&&HF!
hoping for a +ve delta
Anybody else getting 500 server error?
Only on the home page. The contest page works fine: https://atcoder.jp/contests/abc397
D is cancer.
Unfortunately, I have to agree.
Solving the quadratic equation in code is almost always boring.
Although I dislike the particular problem, I still want to thank the authors for the contest.
Not me getting accepted in $$$O(\sqrt{N})$$$ with this code:
No need to solve the thing, just use $$$4*(x^2+xy+y^2)=3*(x+y)^2+(x-y)^2$$$
Problem C : CF DIV4 D but integers instead of char
Problem D : Similar to problem I authored
D >> E
I kept getting 5WA on D, would appreciate if someone point out what's wrong with my code. Basically, I rewirte x^3 — y^3 as (x — y) * (x ^ 2 + xy + y^2). Simply bruteforce every value of x — y from 1 to n ^ (1 / 3).
It might be caused by an overflow when computing $$$delta$$$ or $$$y$$$. You also don't need to check for the solution y=(-3d-k)/6, since y has to be positive
So I guess we don't need to compute delta to solve the problem.
the F problem be solved using decision monotonicity. Is there anyone who can prove this point, or is it wrong?
core code:
https://atcoder.jp/contests/abc397/submissions/63840457
Let $$$ w(i,j) = diff(1,i) + diff(i+1,j) + diff(j+1,n) $$$. Then, to prove the quadrangle inequality: $$$ w(i,j) + w(i+1,j+1) \geq w(i,j+1) + w(i+1,j). $$$
This transforms into: $$$ diff(1,i) + diff(i+1,j) + diff(j+1,n) + diff(1,i+1) + diff(i+2,j+1) + diff(j+1,n) \geq diff(1,i) + diff(i+1,j+1) + diff(j+2,n) + diff(1,i+1) + diff(i+2,j) + diff(j+1,n). $$$
This simplifies to: $$$ diff(i+1,j) + diff(i+2,j+1) \geq diff(i+1,j+1) + diff(i+2,j). $$$
This is easily provable.
Proving the quadrangle inequality is equivalent to establishing decision monotonicity.
The problems are very nice and I solved till F for the first time.
// can u pls help where i am doing wrong in problem d?
You are computing x_cubed where x is going till 1e7, this might cause overflow. Also you are only iterating for x upto 1e7 but there is a chance that both x and y are of the order 1e8 and N is less than equal to 1e18.
G can be solved using PuLP in Python.
See link: https://atcoder.jp/contests/abc397/submissions/63854618
Anyone who used something like topology for E?
I don't want to be impolite.but...isn't D more difficulty than E or F?
(I solved ABCEF in 65min then I spend 30min on D.)
(English is NOT my native language; please excuse typing errors.)
Well,I found another way to understand D without $$$x^3-y^3=(x-y)(x^2+xy+y^2)$$$ or solving the quadratic equation.
Let $$$y=x-k(1\le k \lt x)$$$ because $$$N \gt 0$$$.
Now $$$x^3-(x-k)^3=N$$$,which is equal to $$$3xk(x-k)=N-k^3$$$,so $$$x(x-k)=\frac{N-k^3}{3k}$$$.
Notice that $$$x \gt k$$$ so $$$x-k \gt 0$$$,so we can use binary search to find $$$x$$$.
$$$N-k^3 \gt 0$$$ because $$$x(x-k) \gt 0$$$,so we can enumerate all of $$$k\le ^3\sqrt{N}$$$ and find whether there is an $$$x$$$.
Complexity $$$O(^3\sqrt{N}\log n)$$$.
Don't get the editorial of F. If last[arr[i]]==-1, you add 1 to all elements from 0 to i. Otherwise you add 1 to all elements from last[arr[i]] to i. Then dp[i] is max value in the range 0 to i. Finally you update the value at index i to be suml[i]. How is this computing the answer ? Can someone explain how is this working ?