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

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

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
  • Проголосовать: не нравится

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

fast editorial...orz

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

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

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

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

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

oh wow, thank you for fast editorial

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

What in the Itachi Crow Montage D problem :}

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

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

I never thought that Problem D is a Greedy!

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

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

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

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

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

C was, brutal not gonna lie!

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

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

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

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

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

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

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

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

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

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

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

Problem C is really amazing.

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

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

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

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

sorry i misread the turorial and made a dum comment

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

»
21 месяц назад, скрыть # |
← 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.

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

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

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

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

feeling happy after climbing mountains of problem C

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

»
21 месяц назад, скрыть # |
← 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?

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

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

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

»
21 месяц назад, скрыть # |
← 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.

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

    so what's your conclusion

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

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

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

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

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

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

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

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

Problem Haystacks is so cool, I love it <3

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

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

»
21 месяц назад, скрыть # |
← 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

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

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

In Problem C

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

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

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

»
21 месяц назад, скрыть # |
← 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

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

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

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

Very high quality C and D, loved the round

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

»
21 месяц назад, скрыть # |
← 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!

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

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

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

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

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

»
21 месяц назад, скрыть # |
← 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)

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

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

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

D was amazing

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

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

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

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

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

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

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

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

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

D is too clever and too difficult for me.

»
21 месяц назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
My Observation for problem D
Reasoning
Submission
»
21 месяц назад, скрыть # |
← 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.

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

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