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









500 Internal Server Error showing
ya that is what i am wondering, its in 8 minutes right?
If you try the contests page it works.
thats true, thanks.
thanks for informing :D
How about D? How to do it?
I don't know.
I have AC*28,WA*5.
dont discussing problems during contest
seeing the constraints (pretty low), i simply checked whether reaching a particular xor path length (0-1023) is possible for each vertex v. this was just simple BFS. Finally, i compute the lowest possible xor path length for nth vertex. if no xor value is possible, i output -1
Problem C: This is some text.
The rest of the text.
F is so cooked?
Anybody got some hints? I don't see any observation that makes it simpler?
if $$$n \gt m$$$ then swap n m
Then $$$O(n^2m)$$$ solution can became $$$O(nm\sqrt{nm})$$$
I saw that part, but I don't know how to find the number of rectangles between two column/rows.
List the first and last rows of the rectangle, calculate the sum of the elements in each column between them, and then the problem becomes finding how many intervals there are so that their sum is $$$0$$$. It can be solve easily using "Prefix sum" algo and an array.
What is the O(n^2m) solution?
Nice Bro , how you got this trick ? have u done similar problems before .
https://atcoder.jp/contests/abc410/submissions/66780530
what s wrong with this D ?
directed graphhhhhhhhhhhhhhhhhhhhhhh
How to construct the sequence of operations for problem G, second sample input?
I think E is easier than before. I usually cannot solve E in previous ABCs, but this time I got accepted in 52 minutes.
+1 I agree with you
E is very easy.I solve A,B,CandE.I use Dynamic Programming to solve E.
Can't we solve D by having a path xor of 1 to n (let's call this xn) and then using xn = min(xn, xn^b) for all b where b is one of the basis of xor of all the cycles in the graph connected with the path 1 to n?
My submission: submission
I would like to know for which type of cases this will fail.
In theory, yes. In practice, I'm not sure. Take a look at this problem. Its solution is just like what you mentioned. It is the same question as D except for two differences:
1- The constraint of D are smaller.
2- The graph in D is directed, while this problem has an undirected graph.
I tried to follow the same approach but I could not get it to work on a directed graph. But maybe due to the lower constraints, someone could figure out a way of doing it.
It seems related to directed graphs, but I can't quite pinpoint how.
does your logic work for below kind of graph, which has cycles like this:
suppose the directed graph is like
1->2
2->3
3->4
4->5
5->2
3->6
Yes
People who are downvoting me, it would be good if you also give some hint about why this approach fails.
haven't participated any coding contest for a year, and I just come back here. however i solved E but didn't come up with a solution with D... didn't realize it was just a bfs...
Can anyone give me an idea for problem D? I just can't come up with a solution for the cyclic graph.
Note that there at most 1000 edges, 1000 nodes and each weight is less than 2^10 = 1024, therefore there are at most 1000 * 1024 states, so consider doing bfs
brute force and whenever you reach a vertex v with some xor x, then if you have seen that vertex v with xor x, don't proceed. else keep brute forcing
my submission: https://atcoder.jp/contests/abc410/submissions/66750926
for each node , there are total ((1 << 11) — 1) sate possible . so we just run dfs and ignore same state .. code link => https://atcoder.jp/contests/abc410/submissions/66782080
very nice and elegant soln for E. Might be easy for some, but I couldn't get ahold of the DP idea till the very end.
https://mirror.codeforces.com/blog/entry/143737#comment-1283808
I have used this
does someone how to cheeze the time limit for E with an $$$O(n.H.M)$$$ solution?
Edit: I asked GPT to solve it and this is what it gave. Can someone verify if it is what the editorial meant in their OTHER SOLUTION?
may be bitset can help...it helps reducing t.c of o(n) to o(n/32)
Refer to this blog : (https://mirror.codeforces.com/blog/entry/73558)
is your name vaibhav jain from iit ism
Nope, but I know him
You was going right direction but it will not pass so what we can do is state reduction.
Initially my dp state was depending on three state , now with the optimization shown in the picture I can convert it to two state ..
How??
each time my dp state is depending upon the previous values of h and m so either we can eliminate h or m
1--> eliminating h will result dp[m] --> what is the maximum health I can restore till I use max possible money in this level . If I cannot make even 0 health left it means I was forced to use my health (assumption) even though it was impossible for me so I can't go further break and return i
2--> similarly I can eliminate my magic or money .
dp[h] what is the maximum magic that I can save in this level .
I will use two dp , dp[h] --> for current magic and nxt[h] --> maximum magic that can saved for next state if the health at the very next state is h . Two transitions are possible I am taking the 2nd case
a--> either I can use my health against monster if(arr[i]<=h) then I will go to
nxt[h-arr[i]]=max(dp[h] -- means dont fight , nxt[h-arr[i]] --> fight and have h-arr[i] health for next state with m magic)
b--> or I can use my magic
if(dp[h]>=brr[i] )
nxt[h]=max(dp[h]-brr[i] --> use magic in this state , nxt[h]--> dont use )
Initialize nxt with -1 at starting of all health choices If after all the choices if my maximum element in nxt is <0 it means I cannot have any valid choice return the cnt or value of level (i) .
Here is the code
This is for the first time I am explaining in such huge length of words . Sorry If I failed
Rapidly solve A-F then stuck at G be like:
Can anyone link their solution for E in Top Down Approach ? I was trying to solve it but failing in memoisation part.
this one bro : https://atcoder.jp/contests/abc410/submissions/66761831
I thought in problem E, you can skip the monster, then, BOOM !!!!
The most correct thing I did is abandon E, then do F in last 25 minutes of contest and finally I get AC in F in the last few minutes. If the ranking is calculated in ICPC rules (which means each problem weight equally), then I will totally be finished even if I solve F at last.
Does anyone have an idea how we could solve E if we were allowed to reorder the monsters before starting the game?
Note that reordering will be the same as if we allow to skip monsters. The state this time will dp[pos][magic left] = { monsters killed, max health remaining}
If I understood correctly, $$$dp[pos][magic]$$$ is a pair, and since we are looking for the maximum, when taking the maximum between pairs, the first element is prioritized, so for example, $$$(1, 0) \gt (0, 10)$$$.
Consider the following input:
3 10 1
10 2
1 2
1 2
Here we would not be able to use magic at all, so we would actually be taking a greedy approach that does not work. Since $$$dp[1][1] = max((1, 0), (0, 10)) = (1, 0)$$$, and afterwards we will not be able to fight anymore, so $$$dp[3][1] = dp[2][1] = dp[1][1] = (1, 0)$$$. This is not optimal, since we could fight the second and third monsters with health, and get an answer of 2.
If understood your dp state correctly, then I don't think it has optimal substructure.
Having more health could be better than number of killed monsters, sorting monsters by ascending order of a[i] is needed
Is problem E solvable assuming you could choose the monsters in any order?
This F is harder than before I think.
Could someone tell me why the Bellman-Ford algorithm cannot be used for Problem D?
The correctness of algorithms like Bellman-Ford and Dijkstra relies on the principle of optimal substructure. For additive paths, this means that a shortest path from A to C that passes through B must contain the shortest path from A to B.
This principle does not hold for XOR sums.
well said
bhaiya what do you mean by optimal substructure. can you please elaborate and can you please tell me why djikstra fails here as it also tries all the paths from source to end which will have the xor always min the previous or equal
Why did u use it in the very first place? Maybe to detect Negative Cycle, but was that really needed? Meanwhile if you have used it to find the shortest valued XOR for all the intermediate path, that might not be enough to yield the minimum valued path from 1 to N. Moreover 2 greatest values path xor might yield to a minimum valued path.
Let's consider a graph with 3 nodes and 4 edges.
1 2 1
2 3 2
1 2 1024
2 3 1025
If u have chosen the first two edges in hope of getting the shortest path, u r wrong. It would yield a result of 3, whereas by taking the last 2 edges would yield a result of 1. Hope u have got my point.
Can someone explain why my solution using Dijkstra's for D is incorrect? My submission
bro dijikstra is wrong
let say the there there is only one edge from n and that is n and n-1 with weight x+1 and the path to reach from 1 to n-1 can be x, x+1 as per dijikstra you will take x as the minimum path but that is wrong if you take x+1 as a path then it x+1^x+1 which will end up giving 0 as path cost
bro can you explain me in more , like i had take a example of graph 4 4 1 2 3 1 3 8 3 4 8 2 4 8 still the same result i am getting from Djikstra , can you please explain why normal djikstra fails here as it also storing the min xor from source node to the end node , i have confusion can you please clear
ok bro i got it 5 5 1 2 0 2 3 8 1 4 0 4 3 7 3 5 8 this was the test case where djikstra fails
any recursive dp solution for problem E (without binary search O(n*m))
check editorial. Also, by binary search, do you mean BS on Ans for no. of monsters? Does that also not require some form of a DP?
Used binary search on index and dp to get min possible power use code
What I did for question E reducing state
Initially my dp state was depending on three state , now with the optimization shown in the picture I can convert it to two state ..
How??
each time my dp state is depending upon the previous values of h and m so either we can eliminate h or m
1--> eliminating h will result dp[m] --> what is the maximum health I can restore till I use max possible money in this level . If I cannot make even 0 health left it means I was forced to use my health (assumption) even though it was impossible for me so I can't go further break and return i
2--> similarly I can eliminate my magic or money .
dp[h] what is the maximum magic that I can save in this level .
I will use two dp , dp[h] --> for current magic and nxt[h] --> maximum magic that can saved for next state if the health at the very next state is h . Two transitions are possible I am taking the 2nd case
a--> either I can use my health against monster if(arr[i]<=h) then I will go to
nxt[h-arr[i]]=max(dp[h] -- means dont fight , nxt[h-arr[i]] --> fight and have h-arr[i] health for next state with m magic)
b--> or I can use my magic
if(dp[h]>=brr[i] )
nxt[h]=max(dp[h]-brr[i] --> use magic in this state , nxt[h]--> dont use )
Initialize nxt with -1 at starting of all health choices If after all the choices if my maximum element in nxt is <0 it means I cannot have any valid choice return the cnt or value of level (i) .
Here is the code
This is for the first time I am explaining in such huge length of words . Sorry If I failed
in D, why won't dp[v] = std::min(dp[v], dp[u] ^ w) work. We do it every time even if a node is visited since cycles can be present. Please explain.
Because XOR doesn't work in that way.
let us suppose you are getting 3 , 8 and you select 8
on the next stage let again the wt be 8
no if you would have choose 3 you'll end up having 11 where as if you would have choose 8 then you might end up having 0 as ans. which is actually correct.
So taking min wont help .
can anyone help to figure out the mistake in ques 3
Note that in operation 3, $$$k\le 10^9$$$. So $$$r$$$, which memorized the sum of $$$k$$$ s, had exceeded the range of int. You should use long long int.
Are we possible to solve F in a complexity of less than $$$O(N \sqrt N)$$$?