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

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

Hope you enjoyed the problems!

UPD 1: Added implementations!

UPD 2: It seems my wording for the solution to C is not the best, and it is causing some confusion. I've updated it to be better!

UPD 3: Implementation links didn't work for some reason, so I've just added the code directly.

2055A - Two Frogs

Hint 1
Solution
Implementation

2055B - Crafting

Hint 1
Solution
Implementation

2055C - The Trail

Hint 1
Hint 2
Hint 3
Solution
Implementation

2055D - Scarecrow

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Implementation

2055E - Haystacks

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Implementation

2055F - Cosmic Divide

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Implementation
Разбор задач Codeforces Round 996 (Div. 2)
  • Проголосовать: нравится
  • +142
  • Проголосовать: не нравится

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

fast editorial...orz

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

woah that was fast! we've been getting lots of quick editorials lately, nice!

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

tell me I'm not the one who use lazy segtree on B

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

oh wow, thank you for fast editorial

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

What in the Itachi Crow Montage D problem :}

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

I spent lot of time to figure out C, but then was about to give up without any idea, but then I tried to make a submission by making sum of rows and column Zero, and it worked .. I am not proud. But I hope to get some idea from the editorial.

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

Can someone please tell me why my submission 300745220 for Problem D is failing?

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

    The logic seems correct, but the error may be with the way you print the answer. Your val is long double, so when it becomes large enough, it prints in scientific notation, e.g. 4e+08 instead of 400000000

    Converting to long long should fix that: cout << 2 * (ll)val << endl;

    And generally, as a rule of thumb, if the answer to the problem is an integer, but your variable is a floating point, better always cast it to the int before printing, just in case :)

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

Use binary search, problem C is possible. Really inspiring problem C, I hardly solved it in 90mins.

I feel upset that I didn't solve it like editorials. I should practice more.

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

    its completely normal to have a solution that isnt like the editorials.

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

      I feel my solution was completely complex, did anyone do like this?300738374

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

        Could you explain what are you binary searching on?

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

          We choose any $$$x$$$ to fill $$$(1, \, 1)$$$, then the next cell can be calculate. After $$$n + m - 2$$$ operations, we still remain the last cell of $$$(n, \, m)$$$. Any number $$$a$$$ we choose may not satisfy, the sum of cols and the sum of rows have difference. The difference can be positive of negative(decided by the last operation you do on the row or col). We assume that we operate on the last row, and donate $$$\Delta x = sum_{row} - sum_{col}$$$. If $$$\Delta x \lt 0$$$, we need to enlarge the last number to ensure it can be an equation. So try to enlarge $$$x$$$ and try to fill the cells again.

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

            Hi can you explain why S = 0 works for the case when n == m as then we can have a solution where S can be anything?

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

              Why won't it work? , like clearly S*n = S*m , as you claim(n == m) , they cancel out leaving S = S , which is always true , as it turns out S can be set to any value so obviously S = 0 will work as well....But since when n != m , S needs to be set to zero , then its beneficial for us to always choose s = 0 so that we can do it in a single algo....

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

                got it thanks

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

                  What he said is not correct, how do you even get it? S*n = S*m and canceling doesn't mean anything, you still don't know the value of S.

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

                  Hey S*n = S*n means S will satisfy for every value if you look at this equation only so S = 0 will be one of the solution here in this case you can have any sollution , you can compute S to any random number also in this case and you will get a solution for all values

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

                  In the question some part of the matrix are fixed numbers, you have to prove the S = 0 works based on the given matrix, not just looking at S*n = S*n. It only means you can find a n*n matrix with row and column of sum S and S can be any value but it has nothing to do with the question.

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

                  Again if S = 0 then we can have solve this problem as defined in a approach and we can have one equation and one variable for missing number (0) so we will definitely have a solution and then Sum of all rows and columns will be same so all constraints are satisfied

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

                  Yes, that's what I am talking about. You have to prove it with the approach to say that it works for any integer not because just a S*n = S*n.

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

            Hey. I am not sure I understand your idea of binary searching over sum value but in your code , you will never have more than one iteration as sum=0 in first iteration itself which will satisfy required conditions.

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

            Actually, if we choose $$$x$$$ to fill $$$(1,1)$$$, and donate $$$y = sum_{row} - sum_{col}$$$, we can notice that they have a linear relationship, which means $$$y = k \times x + b$$$. So, we can successively let $$$x = 0,1$$$ and fill the cells, then calculate the value of $$$k,b$$$. After that, let $$$x = -\frac{k}{b}$$$, and fill the cells again.

            My English is quite poor. If you can't understand me, you may check my submission. Some of the implementations in my code differ from the above process to some extent.

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

    I tried to use binary search for C as well here: https://mirror.codeforces.com/contest/2055/submission/300745300

    But I still don't know why it doesn't pass, because from my analysis, my program would eventually search the case where $$$S=0$$$.

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

C was, brutal not gonna lie!

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

    agreed, i had a similar approach to the editorial but i got overwhelmed with the 120 lines of code that i wrote and couldn't debug it in the last 10 mins.

    still, getting this close to solving C being rated 800 feels nice!

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

That's literally what I was trying to do for B and it didn't pass :-| My approach was to create a new array c that's a — b. If there are more than 1 negatives in c (we need to make more than 2 materials) the answer is NO.

Otherwise take the minimum positive in c and check whether it's large enough to turn the negative into 0.

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

even tho i didnt do well this has to be the highest quality div 2 in a very long time

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

man if i didnt get WA due to using int not ll I would rank 1000 places higher

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

Aren't there any code that I can read so I can understand better??

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

questions were good ngl , although i dont know how to even start D

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

Problem C is really amazing.

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

Can someone point out the mistake in my submission for D 300739742. Looking at the editorial feels like my approach is similiar.

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

why this failing for c

// this is code
void solve(){
    ll n,m;cin>>n;cin>>m;
    string s;cin>>s;
    vector<vector<ll> > v(n,vector<ll>(m,-1));
    rep(i,n){
        rep(j,m) cin>>v[i][j];
    }
    
    vector<vector<int> > vis(n,vector<int>(m,1));
    int i1=0;
    int j1=0;
    int x=0;
    vis[i1][j1]=-1;
    while(x<s.length()){
        if (s[x]=='D'){
            i1++;
            vis[i1][j1]=-1;
            x++;
        }
        else{
            j1++;
            vis[i1][j1]=-1;
            x++;
        }

    }

    // rep(i,n){
    //     rep(j,m) cout<<vis[i][j]<<" ";
    //     cout<<el;
    // }
    
    for (int i=0;i<n;i++){
        ll sum=0;
        ll mi=0;
        ll indx=-1;
       
        for (int j=0;j<m;j++){
            
            if (vis[i][j]==-1){
                indx=j;
                mi++;
            }
            else{
                sum=sum+v[i][j];
            }
        }
        if (mi==1){
            
            v[i][indx]=sum*-1;
            vis[i][indx]=1;
        }
    }

    for (int j=0;j<m;j++){
        ll sum=0;
        ll mi=0;
        ll indx=-1;
       
        for (int i=0;i<n;i++){
            
            if (vis[i][j]==-1){
                indx=i;
                mi++;
            }
            else{
                sum=sum+v[i][j];
            }
        }
        if (mi==1){
            
            v[indx][j]=sum*-1;
            vis[indx][j]=1;
        }
    }


    for (int i=0;i<n;i++){
        ll sum=0;
        ll mi=0;
        ll indx=-1;
       
        for (int j=0;j<m;j++){
            
            if (vis[i][j]==-1){
                indx=j;
                mi++;
            }
            else{
                sum=sum+v[i][j];
            }
        }
        if (mi==1){
            
            v[i][indx]=sum*-1;
            vis[i][indx]=1;
        }
    }

    for (int j=0;j<m;j++){
        ll sum=0;
        ll mi=0;
        ll indx=-1;
       
        for (int i=0;i<n;i++){
            
            if (vis[i][j]==-1){
                indx=i;
                mi++;
            }
            else{
                sum=sum+v[i][j];
            }
        }
        if (mi==1){
            
            v[indx][j]=sum*-1;
            vis[indx][j]=1;
        }
    }


    rep(i,n){
        rep(j,m) cout<<v[i][j]<<" ";
        cout<<el;
    }
}
  • »
    »
    15 месяцев назад, скрыть # ^ |
    Rev. 4  
    Проголосовать: нравится +25 Проголосовать: не нравится

    Please use spoiler...

    you can use spoiler like this.

    1) <spoliler>

    2) then three backticks (```)

    3) Then your code.

    4) again three backticks (```)

    5) </ spoiler> ( remove space between / and the spoiler ).

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

Can someone please explain me why my submission 300732331 for Problem C is failing? I thought the way i coded that was the same thing that what written on the solution but i guess there's something i don't understand.

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

sorry i misread the turorial and made a dum comment

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

why in c we have to make sum ==0 of all rows and cols .... why can't we make sum of all rows and col equal max of sum of rows or col or anyother number

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

Considering the difficulty of all the problems, I sincerely wish, if the contest had 2:15 minutes or 2:30 minutes.

I think, I solved D ( passing pretest 1 xD ), right after 5 minutes of contest ending :( .

Code for D, May or May not work.

I don't know, if anyone else solved D, within 10 minutes after the contest.

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

For the problem C, what is the intuition behind trying to make the sums of all rows and columns as 0. In the editorial it is written S.N has to be equal to S.M

But in the problem statement the only requirement is that we need to make sums of all individual rows and column same, am I missing something?

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

I got TLE in problem c. If someone finds the problem please let me know. My solution:- https://mirror.codeforces.com/contest/2055/submission/300745877

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

feeling happy after climbing mountains of problem C

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

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

i submitted 2 correct submissions for problem D(300739717 and 300743089), and 300743089 is just 300739717 with some ints turned into longs. I submitted 300743089 since I was scared that someone might be able to hack it to cause overflow. However, my first submission, 300739717 got skipped because it was almost identical to 300743089, but my second submission 300743089 didn't. Now, I have to incur the extra penalty for the second submission, since i submitted it 8 minutes later than the first. Does codeforces usually do this or should I get the points off of my first submission?

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

    Whenever you have multiple submissions that pass pretests, all but the last are skipped. You could have completely rewritten the code without a hint of similarity between the two submissions, and 300739717 would have still been skipped and ignored.

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

thank you innocentkitten for the wonderful contest and letting catgirl reach master orz

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

Can someone please explain the maths behind C? My observation:

There exists $$$n + m$$$ variables: $$$n + m − 1$$$ values from cells, and the sum $$$S$$$.

There exists $$$n + m$$$ equations: From each row and each column.

So there can be $$$0, 1$$$ or $$$\infty$$$ solutions. But the editorial choosing sum $$$S$$$ implies there are infinite solutions. What is the proof of this?

Update: Nevermind I understood it.

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

    so what's your conclusion

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

      Assume the first sample. Let the unknown numbers be $$$a, b, c, d, e$$$, and the sum be $$$x$$$.

      So the grid is:

      $$$a$$$ $$$2$$$ $$$3$$$

      $$$b$$$ $$$c$$$ $$$d$$$

      $$$3$$$ $$$1$$$ $$$e$$$

      The equations are:

      • $$$a + 5 = x$$$ — $$$(i)$$$
      • $$$b + c + d = x$$$ — $$$(ii)$$$
      • $$$e + 4 = x$$$ — $$$(iii)$$$
      • $$$a + b + 3 = x$$$ — $$$(iv)$$$
      • $$$c + 3 = x$$$ — $$$(v)$$$
      • $$$d + e + 3 = x$$$ — $$$(vi)$$$

      Now, realize that the equations $$$(i)$$$ + $$$(ii)$$$ + $$$(iii)$$$ — $$$(iv)$$$ — $$$(v)$$$ = $$$(vi)$$$

      So equation $$$(vi)$$$ is not giving any new information, it can be derived from the first $$$5$$$ equations.

      So we can conclude that there are $$$n + m$$$ variables and $$$ \lt n + m$$$ equations. So there are infinite combinations of values satisfying these equations, and we have to choose the easiest calculable solution of them.

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

        I would argue that this only happens because, in the first sample, the grid is a square. In any other case, there is exactly one solution for all variables (x = 0)

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

          See it this way, in the first $$$n$$$ equations, each number is considered once.

          In the next $$$m - 1$$$ equations, we'll have each number from the first $$$m - 1$$$ columns.

          So subtracting the $$$n$$$ equations with the $$$m - 1$$$ equations gives the $$$m$$$-th equation.

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

cout << (long long)2*tim << endl; cost me an AC in D

It should have been cout << (long long)(2*tim) << endl;

Very Dumb of me obviously to write that , even very dumb of me to not recognise it in my 15 mins debugging.

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

Can anyone help me with todays B 2055B - Crafting.

My thought was: 300755890 We cannot increase more than one element for sure, why? Because if we try to increase A and B then we will inc. A then we have to dec B by atleast 1 and to inc B by 2 now we have to dec A by 2.

My second observation was that as the inc is dependent on dec so I calulated the minimum decrease that we can do and the max increase that we have to do although it is the single element. Now if the max increase is greater than the min decrease that we can bear than the ans in simply no.

for rest of the cases we can do the task so the ans is yes.

Can anyone please help me where I went wrong ?

Am I too dumb to ask this shit ?

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

EF are way harder than it should be. I've never seen a *3000 div2E.

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

Problem Haystacks is so cool, I love it <3

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

awang11 the implementations are not visible, we "aren't allowed to view the requested page"

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

For me, an easier way to reason about problem D is to think of two cases:

  1. The current scarecrow is to the right, in which case we:
    • bring it closer to the crow by "spending" the time accumulated so far;
    • bring the previous and current scarecrows closer to each other, by half the distance between the crow and the latter, updating the elapsed time as necessary;
    • move the crow forward by $$$k$$$ units plus the distance from the previous step.
  2. The current scarecrow is to the left, in which case we:
    • bring it closer to the crow by "spending" the time accumulated so far;
    • move the crow forward by $$$k$$$ units minus the distance from the previous step (which must be less than $$$k$$$).

At the end, if there remains any distance, the last scarecrow must move forward by that distance (adding to the elapsed time). The special case of the first scarecrow can be handled before the main loop. 300755131

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

I am really disappointed by how nowadays contests are formed, do guys from 1400-1800 have no oppurutunity to solve problems involving some Data structure or algo, I mean this level of greedy upto D, i mean we should give some advantage to guys who have read something extra over heavily intelligent guys who are gud at observing or greedy.

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

In Problem C

Can it be proven that when n=m the solution x=0 is also possible?

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

I appreciate the detailed editorial with hints and everything... also, I enjoyed the contest! :D

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

In C, why is it correct to assert S × n = S × m? Why does the sum of the sum of the rows need to be equal to that of the columns? Oh, I get it, it's just the sum of the grid

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

Nice explanation for problem C, I just guessed that setting x = 0 will work but wasn't able to prove why.

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

Very high quality C and D, loved the round

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

For problem C: The fact that $$$S = 0$$$ will hold when $$$n = m$$$ is not trivial and the editorial's argument is not sufficient for that.

One argument for $$$m = n$$$ is that there are $$$n+m$$$ variables ($$$n+m-1$$$ on the path and $$$1$$$ which is $$$S$$$) but the $$$n+m$$$ linear equations are not linearly independent (since $$$m=n$$$, sum of all columns equal sum of all rows). So, we can pick $$$S$$$ to be anything we want since there are only $$$n+m-1$$$ linearly independent equations.

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

For D, you can multiply l, k, and the entries of a by 2 (but keep the speed at 1), so that you don't need to work with doubles.

Also, the solution to D is well-written, thanks!

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

Problem A is identical to an atcoder task: https://atcoder.jp/contests/agc020/tasks/agc020_a

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

    ah, unfortunate. Given that the problem idea is relatively standard it's not a surprise it's come up before... but since it's problem A there isn't much to be done. Sorry about that.

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

Here's the other way to implement the last part of problem E, which is simpler I'd say. Basically we choose the last haystack in the following way:

If we have a haystack with $$$b_i \le a_i$$$ which can be used as the final haystack, then it's not worse to use it as the last haystack, so we use it and calculate the answer.

Otherwise let $$$f_i$$$ be $$$a_i + \sum_{j \lt i} b_j - a_j$$$, and let $$$g_i = min_{i \le j}(f_j)$$$, then if we move the $$$i$$$-th haystack to the end (if possible) the answer will increase by $$$max(0, b_i - a_i - g_{i+1})$$$. So we choose a haystack that minimizes it.

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

In problem E, can someone elaborate on why this part holds true? "It is not hard to show that all such σ satisfying these properties are optimal by following similar logic as above."

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

Hi Everyone, Here is my intuition for C

I made a linear equation (n + m ) * x = 2 * (total_sum_grid)

(n + m)*x = 2 * (partial_sum + y)

let (n +m) = p , partial_sum = q;

p*x = 2 * (q + y)

p.x = 2.q + 2.y

p.x — 2.y = 2.q (here we know the p , q values)

so after generating equations for test cases I felt this linear equation will always have solutions and x, y values can be any ranging {0 infinity}. So here I was stuck for 20min how can I pick x from this at some point I thought it could be done with binary search but then I realized it won't form 000000011111. since I got stuck I though let's start with a simple thought by fixing x = 0 , I tried few test cases and it is always balancing all rows and columns. But at this point I don't have prof why sticking to x = 0 will work but after few test cases I felt x = 0 will always work (I just assumed my prof as since all column's and rows have same sum and because of the given path I thought I can always adjust all columns and rows as I have few positions to adjust but I know this is not a nice way to prove). Now my issue is how can I implement it as of now from my observations I have x = 0 but how can I traverse the grid in such a way that rows and columns will be adjusted. Then I thought of what is the use of the given path and what will happen when we fix one element in the path given. Here I could see we can always fix a row or column as 0 based on our next step as given in the editorial as we never going to return back to either a row or column. At this point I got confidence that we can always adjust x = 0 why because the path will traverse in such a way that all columns and rows will be adjusted if we travel along the path(as path covers all rows and columns). Even though I got AC on this but after seeing editorial I felt i am just lucky. **I don't know should I feel happy or sad about my solution **.I will be happy with any of yours suggestions. ThankYou.

mysolution 300780643 TC = (N*M + N + M)

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

Can someone tell the exact movements in last test case of the sample test case ?

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

D was amazing

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

I tried binary search for problem D, check for max time T then adjusting scarecrow positions greedily to give max push in right direction 300834214

but not sure why it's failing :(

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

woah that was fast! we've been getting lots of quick editorials lately, nice!

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

Can anyone tell me why this 300740665 solution giving wa in tc2

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

    Some values are still 0 after you do the operations. Consider RDRDRDRDRD... So going row by row: We can't have an answer for row1, row2, row3, row4 and so on Similarly for column, col1 will have the answer but col2, col3, col4 and so on In this case if you do alternate col to row it will work(only in this case). There can be more cases. Come up with some general algorithm.

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

I have WA on B with similar logic as in solution: https://mirror.codeforces.com/contest/2055/submission/300902104 — help plz

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

D is too clever and too difficult for me.

»
15 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
My Observation for problem D
Reasoning
Submission
»
15 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Here's a fun way to skip the optimality claim in E:

The problem is numerically stable, which means we can add infinitesimals to $$$a_i$$$ and $$$b_i$$$ and get essentially the same answer (well, we can't, because $$$a_i$$$ and $$$b_i$$$ are integers, but we can just work with the continuous version of the problem, where we move $$$x$$$ haybales for possibly non-integer cost $$$x$$$).

So if we replace $$$a_i$$$ by $$$a_i + i \varepsilon$$$ and $$$b_i$$$ by $$$b_i - i \varepsilon$$$, $$$\min(a_j, b_i)$$$ and $$$\min(a_i, b_j)$$$ are never equal. Since $$$ \lt _{*} := \min(a_j, b_i) \geq \min(a_i, b_j)$$$ is transitive, we can go ahead and just sort the elements to get $$$\sigma$$$.

...it's probably easier to come up with the constructive solution anyway.

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

I've encountered a tricky problem. These four pieces of code only differ in the comparison function when a_i=b_i, but they yield different results. The comparison function should have no impact.Someone please help me.[submission:301500898][submission:301502091][submission:301501960][submission:301501852]

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

Problem C can be solved in O(n+m-2), i.e., O(n+m), using the precomputed sum of each row and column of the matrix. [Note: Here, I am ignoring the complexity of i/o and col-wise sum calculation.]

IDEA: In the current index (i, j), I will make the current col and row sum 0, but the question is, what should I proceed with first, or can I make both col and row 0 from standing at (i, j)? The answer is no. so if the next step is 'D' I will make the row first zero, and then moving into the row I will make the col sum 0. For the next step 'R' does vice versa.

I am giving the solution here for better understanding,


#include <bits/stdc++.h> using namespace std; #define int long long void _() { int n, m; string s; cin >> n >> m >> s; vector<vector<int>>a(n+1, vector<int>(m+1)); for(int i = 0; i < n; i++) { int s = 0; for(int j = 0; j < m; j++) { cin >> a[i][j]; s+=a[i][j]; } a[i][m] = s; } for(int i = 0; i < m; i++) { int s = 0; for(int j = 0; j < n; j++) { s+=a[j][i]; } a[n][i] = s; } int i = 0, j = 0; for(int k = 0; k < n + m - 2; k++) { if(s[k] == 'D') { int pres = a[i][m]; a[i][m] = 0; a[i][j]-=pres; a[n][j]-=pres; i++; pres = a[n][j]; a[i][j]-=pres; a[n][j] = 0; a[i][m]-=pres; } else { int pres = a[n][j]; a[i][j]-=pres; a[n][j] = 0; a[i][m]-=pres; j++; pres = a[i][m]; a[i][m] = 0; a[i][j]-=pres; a[n][j]-=pres; } } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cout << a[i][j] << ' '; } cout << '\n'; } } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { _(); } }
»
11 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

B。。。Why did you write a Merge Sort,I can't understand........ If you just wanted to spoof new talent,I can't say that I am unrated....

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

For problem C, why does x = 0 always work? However, when x is equal to random value, say 61, it fails (even when n == m)?

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

Reniasggscaer

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

In C.

What if grid is 2X3

0 10^6 10^6

0 0 0

10^6 10^6 0

DRRD

We have to fill a[0][0] as -2*(10^6) but the minimum value of a cell can be -10^6. How will this test case work?