Блог пользователя atcoder_official

Автор atcoder_official, история, 10 месяцев назад, По-английски

We will hold AtCoder Beginner Contest 410.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +58
  • Проголосовать: не нравится

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

500 Internal Server Error showing

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
int rp = 0;
while (contest.end != true) rp++;
cout << rp << endl;
»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится -56 Проголосовать: не нравится

How about D? How to do it?

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится -11 Проголосовать: не нравится

Problem C: This is some text.

// this is code
void inc(int pos, int d) {
    for (; pos < n; pos |= pos + 1)
        f[pos] += d;
}

The rest of the text.

»
10 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

F is so cooked?

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

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to construct the sequence of operations for problem G, second sample input?

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think E is easier than before. I usually cannot solve E in previous ABCs, but this time I got accepted in 52 minutes.

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

E is very easy.I solve A,B,CandE.I use Dynamic Programming to solve E.

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

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?

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
10 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится

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?

  • »
    »
    10 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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)

  • »
    »
    10 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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

    for (int i = 0; i < N; ++i) {
        fill(nxt.begin(), nxt.end(), NEG);
        for (int h = 0; h <= H; ++h) if (dp[h] != NEG) {
            if (h >= A[i])
                nxt[h - A[i]] = max(nxt[h - A[i]], dp[h]);
            if (dp[h] >= B[i])
                nxt[h] = max(nxt[h], dp[h] - B[i]);
        }
        if (*max_element(nxt.begin(), nxt.end()) == NEG) break;
        dp.swap(nxt);
        ++defeated;
    }
    
    
    

    This is for the first time I am explaining in such huge length of words . Sorry If I failed

»
10 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
10 месяцев назад, скрыть # |
Rev. 4  
Проголосовать: нравится +9 Проголосовать: не нравится

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.

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    10 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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}

    • »
      »
      »
      10 месяцев назад, скрыть # ^ |
      Rev. 4  
      Проголосовать: нравится 0 Проголосовать: не нравится

      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.

    • »
      »
      »
      10 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

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

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

This F is harder than before I think.

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    10 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

  • »
    »
    10 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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
»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    10 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    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

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

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

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

for (int i = 0; i < N; ++i) {
    fill(nxt.begin(), nxt.end(), NEG);
    for (int h = 0; h <= H; ++h) if (dp[h] != NEG) {
        if (h >= A[i])
            nxt[h - A[i]] = max(nxt[h - A[i]], dp[h]);
        if (dp[h] >= B[i])
            nxt[h] = max(nxt[h], dp[h] - B[i]);
    }
    if (*max_element(nxt.begin(), nxt.end()) == NEG) break;
    dp.swap(nxt);
    ++defeated;
}

This is for the first time I am explaining in such huge length of words . Sorry If I failed

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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
  • »
    »
    10 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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 .

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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; }
»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Are we possible to solve F in a complexity of less than $$$O(N \sqrt N)$$$?