atcoder_official's blog

By atcoder_official, history, 18 months ago, In English

We will hold AtCoder Beginner Contest 410.

We are looking forward to your participation!

  • Vote: I like it
  • +58
  • Vote: I do not like it

| Write comment?
»
18 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

500 Internal Server Error showing

»
18 months ago, hide # |
 
Vote: I like it -56 Vote: I do not like it

How about D? How to do it?

»
18 months ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

F is so cooked?

Anybody got some hints? I don't see any observation that makes it simpler?

  • »
    »
    18 months ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it +5 Vote: I do not like it
    Spoiler1
    Spoiler2
    • »
      »
      »
      18 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I saw that part, but I don't know how to find the number of rectangles between two column/rows.

      • »
        »
        »
        »
        18 months ago, hide # ^ |
        ← Rev. 3  
        Vote: I like it +5 Vote: I do not like it

        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.

    • »
      »
      »
      18 months ago, hide # ^ |
      ← Rev. 2  
      Vote: I like it 0 Vote: I do not like it
      Spoiler
    • »
      »
      »
      18 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Nice Bro , how you got this trick ? have u done similar problems before .

»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
18 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

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?

  • »
    »
    18 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    My submission: submission

    I would like to know for which type of cases this will fail.

  • »
    »
    18 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    People who are downvoting me, it would be good if you also give some hint about why this approach fails.

»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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...

»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone give me an idea for problem D? I just can't come up with a solution for the cyclic graph.

»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.

»
18 months ago, hide # |
← Rev. 2  
Vote: I like it +5 Vote: I do not like it

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?

»
18 months ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

Rapidly solve A-F then stuck at G be like:

»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone link their solution for E in Top Down Approach ? I was trying to solve it but failing in memoisation part.

»
18 months ago, hide # |
← Rev. 4  
Vote: I like it +9 Vote: I do not like it

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.

»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Does anyone have an idea how we could solve E if we were allowed to reorder the monsters before starting the game?

  • »
    »
    18 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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}

    • »
      »
      »
      18 months ago, hide # ^ |
      ← Rev. 4  
      Vote: I like it 0 Vote: I do not like it

      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.

    • »
      »
      »
      18 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Having more health could be better than number of killed monsters, sorting monsters by ascending order of a[i] is needed

»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is problem E solvable assuming you could choose the monsters in any order?

»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could someone tell me why the Bellman-Ford algorithm cannot be used for Problem D?

  • »
    »
    18 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

  • »
    »
    18 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

    Example
»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone explain why my solution using Dijkstra's for D is incorrect? My submission

  • »
    »
    18 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    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

»
18 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

any recursive dp solution for problem E (without binary search O(n*m))

»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.

Spoiler
»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can anyone help to figure out the mistake in ques 3


#include <bits/stdc++.h> using namespace std ; void sitaram(){ int n , q ; cin >> n >> q; vector<int>v(n+1); for(int i =0;i<=n;i++)v[i]=i; int r = 0 , l = 0 ; while(q--){ int t ; cin >> t; if(t==1){ int p , x ; cin >> p >> x ; if((n+p-l)%n==0)v[n]=x ; else v[(n+p-l)%n]=x ; } else if(t==2){ int p ; cin >> p ; if((n+p-l)%n==0)cout << v[n] << endl; else cout << v[(n+p-l)%n] << endl; } else{ int k ; cin >> k ; r+=k ; l = n - r%n ; } } } int main() { sitaram(); return 0; }
  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.