ahsoltan's blog

By ahsoltan, history, 10 months ago, In English

2122A - Greedy Grid

Solution
Bonus

2122B - Pile Shuffling

Solution
Bonus

2122C - Manhattan Pairs

Solution

2122D - Traffic Lights

Solution
Bonus

2122E - Greedy Grid Counting

Solution
Bonus

2122F - Colorful Polygon

Solution
Bonus

2122G - Tree Parking

Solution
Bonus
  • Vote: I like it
  • +171
  • Vote: I do not like it

»
10 months ago, hide # |
 
Vote: I like it +27 Vote: I do not like it

Thanks for the editorial. B gave me cancer.

»
10 months ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

Does this paper essentially solve F?

»
10 months ago, hide # |
Rev. 2  
Vote: I like it +13 Vote: I do not like it

thanks for quick editorial.. although I got cooked in this round by problem C

»
10 months ago, hide # |
Rev. 2  
Vote: I like it +15 Vote: I do not like it

Thanks for the fast editorial :)

D is a good problem but it's too hard for a div.2 D.

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

    yeah only around 500 people solved it even when div1 is included, if we see previous div2 contest .. more than 1000 people are able to solve D.

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

    I have another approach and it wasn't not working, however it had a correct complexity. In my approach I had both MLE and TLE, and it was implementation heavy.

»
10 months ago, hide # |
 
Vote: I like it +110 Vote: I do not like it

After solving G, I felt that it would be easier to use OEIS for the whole problem... I don't think it's good.

The induction part (or "OEIS part") in the editorial can also be replaced with a simple bijection: Consider the DFS order, visiting the larger child earlier. Then a leaf corresponds to a descent.

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

    Yeah, I heavily dislike the fact that the main difficulty point of this problem can be resolved by simple OEIS search. But this was also educational in the sense that I should try to think less and brute force more when I see a counting problem.

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

      Educational in the sense than even now, something like this can still appear as a final problem in a contest.

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

In problem B, why can't it be

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

    we cant move ones before zeros. Only top element can be removed

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

    we can do this , i did exactly this, dont forget to add contribution of zero transfers

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

    I did exactly this way and it wasn't accepted, but a friend of mine did if(a[i] <= c[i]) { steps += a[i] } else { steps += c[i] } steps += b[i] — d[i] and it was accepted. I really want to know what is the difference between these two methods.

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

      Yea you move a 1 only when there are least number of zeroes possible before it. If you can remove a zero before adding a 1 then do it, because the lesser the number of zeroes before a 1, the better. And if you have to add a zero, first remove the ones then add the zeroes.

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

        I did this exactly way and my code was not accepted.

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

          Yea I think you are not considering that if a[i] > c[i], then you remove all the zeroes and set a[i] = c[i], only then can you do the remaining operations. Check my code once, you'll get what I'm saying

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

    see my solution once, its similar to your idea

  • »
    »
    10 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it
    #include<iostream>
    #include<vector>
    #define int long long
    using namespace std;
    signed main()
    {
    	ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    	int t; cin >> t;
    	for (int p = 0; p < t; p++)
    	{
    		int n; cin >> n; int sum1 = 0; int sum2 = 0;
    		for (int i = 0; i < n; i++)
    		{
    			int a, b, c, d; cin >> a >> b >> c >> d;
    			if (c > a) sum1 += c &mdash; a;
    			if (b > d) sum2 += min(a, c) + (b &mdash; d);
    		}
    		cout << sum1 + sum2 << endl;
    	}
    	return 0;
    }
    

    This is my code.Do you mean this? The code can accpet the question

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

      Why

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

        I don't know your concrete confuse. there is my idea:

        We can start by considering zeros first. Since the movement of zeros is independent of ones, we just need to check which positions are short of the corresponding number of zeros. By counting these deficits, we get the total number of moves required for zeros. Then we move on to consider ones. The movement of ones actually involves two steps: first, removing the excess ones, and second, moving all the zeros above them. In this process, the minimum number of zeros that need to be moved is given by min(a, c).

»
10 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

How does the checker for F work?

»
10 months ago, hide # |
 
Vote: I like it +433 Vote: I do not like it

Hilarious but I actually came up with problem D 3 years ago, proving that answer is $$$\leq 2n-3$$$, but during the contest I completely forgot about this, submitting some bullshit. Here is my original proof writeup translated from Ukrainian.

We can restate problem as follows: there is an initial message in node $$$1$$$; once node $$$v$$$ gets a message, it starts transmitting it to its neighbors in arbitrary order. What's the smallest time until the message reaches node $$$n$$$?

Answer: $$$2n-3$$$

Solution. Consider a path on $$$n$$$ vertices in which vertex $$$i$$$ is connected only to $$$i-1$$$ and $$$i+1$$$.
Let each vertex $$$i$$$ ($$$2\le i\le n-1$$$) first send a message to vertex $$$i-1$$$ and then to $$$i+1$$$ (if it exists).
Clearly, vertex $$$n$$$ receives the message at the end of second $$$2n-3$$$.

Now we prove that every vertex is reached within $$$2n-3$$$ seconds.

Let $$$S_i$$$ be the set of reached vertices after second $$$i$$$.
A vertex $$$v\in S_i$$$ is called alive if it has at least one edge leaving $$$S_i$$$.
For every $$$v\in S_i$$$ define $$$d_{v,i}$$$ to be the number of neighbours of $$$v$$$ that lie in $$$S_i$$$ and to which $$$v$$$ has not yet sent a message.

We maintain integers $$$\bigl[\ell_i,\dots,r_i\bigr]$$$ such that the multiset $$$( d_{v,i} | v\in S_i )$$$ is majorized by the sequence $$$\bigl[\ell_i,\ell_i+1,\dots,r_i\bigr]$$$.
Initially $$$\ell_0=r_0=0$$$. Let's update them as we transition to the next second.

Case 1. No new vertices are reached in second $$$i+1$$$. Every alive $$$v\in S_i$$$ uses one of its edges inside $$$S_i$$$, so $$$d_{v,i+1}=d_{v,i}-1.$$$ Hence the multiset is now majorized by $$$\bigl[\max(0,\ell_i-1),\,\dots,\,r_i-2,\,r_i-1\bigr]$$$

Case 2. $$$k\ge 1$$$ new vertices get message in second $$$i+1$$$. For a new vertex $$$v$$$, $$$d_{v,i+1}\le (r_i-\ell_i+1)+(k-1)$$$, while for an old $$$v\in S_i$$$, $$$d_{v,i+1}\le d_{v,i}+(k-1)$$$. Thus the new degree multiset of alive vertices in $$$S_{i+1}$$$ is majorized by $$$\bigl[\ell_i+k-1,\,\dots,\,r_i+k-1,\, (r_i-\ell_i+1)+(k-1),\,\dots,\,(r_i-\ell_i+1)+(k-1)\bigr]$$$ which itself is majorized by $$$\bigl[\ell_i+k-1,\;\ell_i+k,\;\dots,\;r_i+2k-1\bigr]$$$

Consequently, if $$$k_i$$$ vertices are added in second $$$i$$$ (either $$$k_i=0$$$ or $$$k_i\ge1$$$), the choices $$$\ell_{i+1}=\ell_i+k_i-1, r_{i+1}=r_i+2k_i-1$$$ preserve the majorization property.

Suppose not all vertices are reached after $$$2n-3$$$ seconds; then some vertices remain alive.
However, $$$r_{2n-3}=r_0+\sum_{i=1}^{2n-3}(2k_i-1)=0+2(n-2)-(2n-3) = -1$$$ which is impossible. Hence every vertex is reached within $$$2n-3$$$ seconds.

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

    For a new vertex v, dv,i+1≤(ri−ℓi+1)+(k−1), while for an old v∈Si, dv,i+1≤dv,i+(k−1)

    I'm unclear on how we get to this...

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

Thanks for this btw when will be rating changes waiting...

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

I was curious to know that what is Problem Locked verdict on someone's submission. How's that achieved? If someone could share..

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

      thanks for sharing the blog, can you tell me, how can one lock his submission?

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

        From the Dashboard where you can see all the Problems, you have a lock icon besides the star.

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

        after getting accepted, you can lock problem by just clicking on the lock icon

        image

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

          cool, thanks!

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

            im just curious you've been on CF for 2 years, how you don't know about it?

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

              Ohh, i get that, it is so obvious to think, why i didn't know this. Actually, i noticed it many times but i was not getting any clue, how can i lock my problem, so i thought maybe its from the system that if a solution is too good that it cant fail on any pretest then the system locks it. So naive of me to think :) Also, i was not so active in comment section so far, so i never bother to ask but couldn't stop myself this time

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

can somebody please explain problem B?

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

    The tutorial is well explained but I'll try to explain it clearly. You only have to count how many elements you have to remove, because you can put each element you remove in its final position. So, iterating though each pile, if in one pile you have more 1s than target, you have to remove all the 0s and the exceeded 1s, add that to the result. If not, check the 0s, if you have more 0s than target, add the difference between initial 0s and target 0s. I hope it's more clear now.

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

      understand! thank youu

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

      why can't we move 1 to top suppose we have more zeroes at top and we need to remove just extra 1 from the pile we move it to the top in same pile and then move it to other pile.

      why its fixed that we remove the 0's first and all?

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

Wow, this contest made my brain TLE for sure

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

why complexity for B O(N^3)>>???

»
10 months ago, hide # |
 
Vote: I like it +40 Vote: I do not like it

I solved D at 0:21 (and even got an intermediate result of global top-2!). It is hilarious that I spent literally less then a minute thinking about bounds and told myself: we can solve in $$$10\,000$$$ steps because after each step we wait no more than $$$deg(v)$$$ and we know $$$\sum deg(v) = m$$$ and we know $$$n\sim m \sim 5000$$$, right?

I feel I got really lucky. In retrospective it seems really not obvious why 10k is enough. Definitely kind of "I believe this should work" problem, idk if this is good for Div2D.

»
10 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

B was just too unintuitive for me—I couldn't figure it out.

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

Can anyone give me a testcase why this code 329867964 for d fails?

»
10 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

50 mins to solve B by analyzing. 20 mins to solve D by guessing.

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

    I saw a ~10% AC rate on D and I got scared so I didn't guess at once... turns out brute force is right and I don't know what's the main reason everyone is getting WA#2

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

      Not sure what qualifies as Brute Force, but the solution doesn't seem like it to me.

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

        Yeah I might have a wording problem :( It's just a straightforward approach of time complexity $$$O(nt)$$$ where $$$t$$$ is the answer but I'm not sure what $$$t$$$ is. However I can't think of anything else so I coded that anyway.

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

Can anyone explain me the solution of C in simple way?? The editorial went over my head :(

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

    What I did: I sorted the points by the X and divided the points in 2 groups, the leftmost n/2 and the rightmost n/2. Then I sorted both groups by the Y and after that I paired the first point of the 1st group with the last point of the 2nd group and so on. I can't tell why that works but it was accepted.

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

      How did you come up with that approach

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

        I was trying to get the lines crossed each other, I thought that could be a way to do it. What you can't have are 2 lines (p1,p2) and (p3,p4) where both p1x and p2x are less than p3x and p4x (the same for Y).

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

      it's actually right.

      consider you have an sorted array a[] of length 2n. you want to pair them up so that sum(|a[p[i]]-a[q[i]]|) is maximum. this condition is equal to that there aren't two pairs (a[x1] a[y1]) (a[x2] a[y2) (x1<y1,x2<y2) that x1<y1<x2<y2.

      if the p is a permutation of 1~n, q is a permution of n+1~2n, it's obviously that this condition is satisfied.

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

        can you please simplify what you're saying. I don't see why would sorting by x first and then sorting both halves by y be optimal.

        • »
          »
          »
          »
          »
          10 months ago, hide # ^ |
          Rev. 3  
          Vote: I like it 0 Vote: I do not like it

          Its like using diagonals so if I say what is the distance between x = 0 and x = 5, it'd be 5, but if we say distance between (0,0) and (5,5) ? It will equal 7.07, same applies here, we're trying to maximize the distance between the points so we cut the grid into four quarters and save the points into four different containers for each quarter respectively.

          Tldr, we pair from the quarters opposite to each other diagonally.

          Hope it helps, and if I said anything wrong someone correct me.

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

      This is infinite iq approach (• — •)ゝ

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

Can anyone tell in B, if b>d why we do a+(b-d).. a is number of zeros but isn't it optimal to first give maximum zeros to other number possible that is reduce a to c(final state) and then do c+(b-d)?

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

    But to remove 1, first you have to remove the total number of zero above it.

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

      My point is why to remove all zeros if we can give zeros when a>c then reduce a to c and then give b

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

        How will you reduce 1, without removing all the zeroes on top of it?

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

          If a>c first we will give a-c zeros this leaves c zeros in pile which is obviously less than a now let's say we have b>d in same pile and we have to give 1's so shouldn't we shift c remaining zeros instead of a? That is c+(b-d)

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

      For a[i]<c[i] or b[i]<d[i] what to do

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

        If a[i] < c[i] and b[i] < d[i], then you have to do nothing, because the answer always exist as mentioned in problem, because for some other values where a[j] > c[j] or b[j] > d[j], you are going to remove the zeroes or ones, those zeroes or ones will compensate the first case where a[i] < c[i] and b[i] < d[i]

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

    You have to remove minimum number of zeroes for this case. So here the answer would be min(a, c) + (b — d)

»
10 months ago, hide # |
 
Vote: I like it +83 Vote: I do not like it

Is D too difficult for a D? The upper bound analysis of this problem makes me think it has the difficulty level of F.

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

    its rating is 2300, definitely not F

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it -26 Vote: I do not like it

    Problem difficulty isn't based on how hard it's to prove, it's based on how hard it's to stumble upon the solution. In this case, guessing that it works is easier than proving, so that's taken as the difficulty.

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

    For some reasons some contests are ordered by guess difficulty rather than by difficulty to actually solve (I guess it would be worse if such a guessable problem was at F, but it's not really that much better at D).

    It would be better to use such problems on math contests rather than programming contests, but as it is I guess the meta on Codeforces really is just to guess...

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

      In a math contest, it'd most likely be about finding a tight bound, which fundamentally changes how a proof can be approached. In a programming contest, it's very very common to make something that resembles a proof but isn't one because the objective is different — you don't need to know if the bound on time is $$$10N$$$ or $$$2N$$$, only that it should be low enough that your suboptimal code will fit into time and memory limits. You can start by writing a code and analysing it instead. You can generate many smaller graphs. Actual runtime is affected by cache efficiency here so maybe you need to optimise that, depending on your implementation — the time limit is kinda tight. You need to fit into memory. After experimenting a bit, getting rough insight into the problem, maybe you'd come up with a proof much easier.

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

        proving the answer is O(n) also makes for a decent math problem (but easier). A lot, and I mean a lot of people did not even have any idea why the answer is O(n), or had a fake proof for their solution. You are one of the few exceptions.

        I did not even read constraints on $$$M$$$ and just assumed it would be small too.

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it -13 Vote: I do not like it

    Please, calm down bro. You can't denigrate a problem only because you have not come up with its solution quickly during contest or lost rating.

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

      You don't get it, I haven't talked to a single person that proved their solution during the contest. Some people did try but their proof is wrong.

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

        Hi I proved it. Took me like 10 min.

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

          The 3 people at around 2900 rating that I talked to didn't, maybe that's why they're doing that well.

          • »
            »
            »
            »
            »
            »
            10 months ago, hide # ^ |
             
            Vote: I like it -51 Vote: I do not like it

            That's basically coping on your skill issue. you can be 3500 and have problem solving something, people's mind work differently, there is no reason to disrespect. and also, a 2900 in the contest wouldn't care as much to prove it, maybe he just wanted to for fun or smth. why the disrespect

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

              Why don't you come at me with your real account? I'm not disrespecting anyone.

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

does state graph work for D?

»
10 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

thx for the editorial, C teach me some new things.

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

D was cool but I'm sad my python didn't go through even though the complexity seems ok-ish, why limits are not more lenient here?

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

    I think O(N^2logN) wasnt meant to pass With C++ it TLEs in pretest 8

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

      I also tried N^2 after the contest. I'd also say cutting n^2lgn is a bit too much

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

wtf is B bonus ?

»
10 months ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it

in problem C this was my approach

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

    Can u explain how the function simplfies to max(xp,xq)+max(yp+yq)

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

      just substitute it you will get $$$\sum_{p, q}^{all pairs}2 \times (max(x_p, x_q) + max(y_p, y_q)) - (x_p + y_p + x_q + y_q)$$$ break these summations and the second part is always constant and same.

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

        Oh i think i get it. The formula for max(a,b)=a+b+|a−b|/2 is the key! Great

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

    Wow, loved the idea, the logic max(a,b)= (a+b+|a-b|)/2 did just appear in the last div3 round

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

    I wanna know why we can optimize the value of y under the condition that x is optimal. Why this approach can guarantee that y is the optimal choice?

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

Loved the problems, B was too much fun!

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

lmao for problem d i just guessed something like: in the best way every "relax" operation that maybe make the first answer bigger (but can make the second answer smaller) will be done at most 20 times for every vertex. so anyone can hack? plzplz

»
10 months ago, hide # |
Rev. 2  
Vote: I like it -13 Vote: I do not like it

What a great set of questions! The difficulty level is just right, covering a wide range of knowledge points. Moreover, the questions are based on practical scenarios, and the solutions are quite natural. A big thumbs up to the question setter!

题出的好!难度适中,覆盖知识点广,题目又着切合实际的背景,解法比较自然。给出题人点赞!

ps:This is irony.

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

This was a great round , B was nice , C was on an idea that i saw for the first time so got to learn something new from C itself . Looking forward for more rounds by Order Capital.

»
10 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

i think D is too hard that due i got a lot of "Wrong Answer On Pretest 2" :(

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

In problem A for m = n = 2 why cant we have a grid like

1 900
2 3

max greedy path has sum = 1 + 2 + 3 while max path is 1 + 900 + 3

therefore the answer should be "YES"

Someone tell me where I am wrong ?

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

    greedy path is 1+900+3

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

      why i couldnt understand

      A path in a grid is called greedy if it starts at the top-left cell and moves only to the right or downward, always moving to its neighbor with the greater value (or either if the values are equal).

      so according to this unvisited neighbour of 900 is 3 which is neither greater than or equal to 900 so it cant go there if we follow the definition of greedy path.

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

Holy moly, div 1~2 is different from div 2., with just solving 3 question I got +delta

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

Is there a solution for C, where the 2d coordinates are transformed into 1d form, and then the smallest and biggest are paired? (my thought process throughout the contest was to transform the coordinates somehow. But the transformations resulted in scaling the manhattan distance)

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

Here is my solution for problem D which passed system tests, but I was unable to prove it. I hope either someone will hack it or provide the proof: Let's first try to minimize total time. I just have state (i, x) for being in vertex i and trying to go on x-th edge outgoing from i. After this my assumption was that in optimal solution (considering minimizing waiting time) you never need to arrive more than n minutes late compared to earliest arrival time in any vertex. But as I said above, I was unable to prove it. Any counterexamples or insights will be appreciated.

  • »
    »
    10 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +8 Vote: I do not like it

    I wrote this exact same solution. I thought I proved it during the contest, but after the contest I realized my proof was wrong. I asked many 2600+s and none of them proved it. Maybe the answer is really small(<=2n-3) so there is no counter ex for the +n bound.

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

    Hey can you tell me what you did in your code. We can prove that all vertices are reachable in maximum $$$2n - 3$$$ seconds. I understood that part, but I am unable to understand your implementation.

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

      firstly, I calculated earliest arrival time for each vertex. Then, as mentioned above, I assumed that you don't need to arrive more than n minutes later than earliest arrival time for each vertex. Now graph states become (v, t) where v is the vertex you are currently and t is time passed relative to earliest arrival for this vertex. We need to calculate minimum waiting time. We have transitions from (v,t) to (v, t+1) with cost 1, and transition to (to, current_time — D[to] + 1) with cost 0, where to is vertex where we can go and D[to] is earliest possible arrival in this vertex.As costs are 0/1 we can use 0/1BFS

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

Problem C is very conceptual,to learn this like putting another weapon in the algo storeroom.

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

How to solve Problem C if the goal is to minimize the sum of Manhattan distances? Any ideas or approaches?

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

I am newbie got 403 Rating after first contest(Div 3) , if i will able to solve only 1 problem in Div2 will my rating will increase or decrease

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

does same solution work for $$$C$$$ in 3D case?

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

    No. It's not always possible to find a matching optimal for all three dimensions, for example

    (0, 0, 0)
    (1, 1, 0)
    (1, 0, 1)
    (0, 1, 1)
    answer = 4 < 6
    
    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      can you explain for the 2D thing the editorial says to match Xl∩Yl with a point in Xr∩Yr but how to implement this idea and also which point to choose from both the sets.

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

In B,I wrote an O(n) solution in the contest.

submission

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

What exactly is the issue with my implementation?? My submission.

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

would it be possible to solve problem D with some kind of dijkstra approach?

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

dude made me spent all my time i had left still get wrong answer on pretest 2 i couldnt see that so i dont know what to fix (ik im not that good but yeh b is so hard)

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

Am i missing some edge case or what do i need to optimize in this for B if(a>c) { sum=sum+(a-c); a=c; } if(b>d) sum=sum+a+(b-d);

This is wrong for test case 7 it says . What am i missing :(.....

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

https://mirror.codeforces.com/contest/2122/submission/329995334

Can someone help me with this.Its TLE on 9th test even though as per me i have a O(N) soln.

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

    your solution is O(N) — not sure what is causing the TLE. Try to use '\n' instead of endl as it speeds up the output (endl is flushing the output buffer which is not a fast operation whearas with '\n' the buffer only flush when it's full or when the program terminates)

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

    You are missing two critical lines

    std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr);

    never forget this in your C++ code

»
10 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

-

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

How to finish E in O(nk)?

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

For E,how to do it in O(nk)?

I can only come up with a solution in O(nklogk) though using convolution in state transition

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

    Why convolution? The state transitions are just ("add anything between 1 and $$$K$$$" or "add fixed number") and ("subtract anything between 1 and $$$K$$$" or "subtract fixed number"). Prefix sums should be enough.

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

      I'm so sorry,but I still don't know how to do in O(nk) though prefix sums.

      I read your code(329839824) and my code(330058406).Such as your code,the dp[i+1][j_nxt] = (dp[i+1][j_nxt] + dp[i][j] * cnt_dif[dif + (K-1)]) % MOD;//j_nxt=j+difseems like only using convolution. Could you help me? I sincerely thank you. Please forgive my worried English.

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

        There's no point in reading my code, I didn't overoptimise for that bonus.

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

          Thank you all the same!I know that the cnt_dif is special so that we can cauculate the result in O(nk)

          • »
            »
            »
            »
            »
            »
            10 months ago, hide # ^ |
            Rev. 2  
            Vote: I like it -19 Vote: I do not like it

            Our English teacher will cry after she sees your broken English.

            Dear autumoon , I'm sorry .

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

            Through further reflection, I discovered that for an $$$f(z) \times g(z)$$$, if each coefficient of $$$g(z)$$$ can be expressed by a $$$k$$$-degree polynomial, then it can be computed in $$$O(nk^2)$$$ time.

            Specifically, consider the target exponent $$$s = i + j$$$. By replacing each indeterminate in the polynomial expressing $$$g(z)$$$'s coefficients with $$$s$$$, we obtain a coefficient polynomial for each power term. This polynomial should treat $$$s$$$ as the variable, with coefficients derived from the original polynomial. Ultimately, this can be transformed by incorporating the exponent into $$$f(z)$$$ and computing the result via prefix sums. The coefficients of each prefix sum are then determined based on the exponent of each term in the resulting polynomial.

            For example, given $$$f(z) \times g(z) = h(z)$$$ where $$$g(z) = \sum (b + k i) z^i$$$, we have:

            $$$ \begin{aligned} [z^n]h(z)&=\sum_{i=0}^n f_ig_{n-i}\\ &=\sum_{i=0}^nf_i(b+kn-ki)\\ &=\sum_{i=0}^n-k(i\times f_i)+(b+kn)\sum_{i=0}^nf_i \end{aligned} $$$

            This can be computed by maintaining the prefix sums of $$$i \times f_i$$$ and $$$f_i$$$.

            When $$$g_x$$$ is a linear function, this approach applies. Higher-degree cases can be handled similarly.

            The translation was finished by Deepseek because my English is too terrible.

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

In problem B, How would it work for test case 1 ( number of test Case) 2 ( number of piles) 5 4 4 3 ( pile 1 state) 2 2 2 2 ( pile 2 state)

As per my understanding answer should be , 1 , by taking top 0 from first pile and placing it between 3rd and 4th 1 from bottom. Could you please help me with this ?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
void solve()
{
    int n ; cin>>n;
    int cnt = 0;
    foru(n){
        int a , b, c, d;
        cin>>a>>b>>c>>d;
        if(a == c && b>d){
            cnt +=  a + b-d ;
        }
        if(a>c && b==d){
            cnt+= a-c;
        }
        if(a>c && b>d){
            cnt+= a-c + c + b -d;
        }
        if(a<c && b>d){
            cnt += a + b-d;
        }
        if(a>c && b<d){
            cnt+= a-c;
        }
    }
    
    cout<<cnt<<endl;
 
 
}

This is how i did problem number B.

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

ahsoltan can you please add the implementations

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

Problem B. Pile Shuffling ***** think about below test-case 1 3 2 5 1 3 2 4 2 4 1 3 1 3

what should be answer? 4 right?

but think, we move top 0 from first pile and put it at the 4th position from bottom at pile itself it'll look like 0 1 1 0 1 1 1 hence, one 0 at the top and 3 ones at the bottom, which is required. for rest of the piles no changes required

so answer should be 1 not 4 there is no clarifacation about after performing operations, sum of zeroes and ones euals to the sum of top zeroes(target) and bottom ones(target)

»
10 months ago, hide # |
Rev. 4  
Vote: I like it +42 Vote: I do not like it

Here is the solution to G-Bonus (solution using purely generating functions).

if we let $$$T_{n,l}$$$ represent the number of valid permutations on all labelled trees with $$$n$$$ vertices and $$$"l$$$ leaves, and let

$$$t(x,y) = \sum_{n=0}^{\infty} \sum_{l=0}^{\infty} \frac{1}{(2n)!(n)!} T_{n,l} \ x^n y^l$$$

then we have the following recurrence relation

$$$T_{n,l} = \displaystyle\sum_{\substack{\forall \ (n_1,\cdots,n_r) \\ n_1 + n_2 + \cdots + n_r = \mathbf{n-1} \\ n_1 \leq n_2 \leq \cdots \leq n_r}} C(n_1,\cdots n_r) \cdot \frac{(2(n_1 + \cdots + n_r) + 1)!}{(2 \ n_1)!\cdots (2 \ n_r)!} \sum_{\substack{l_1 + \cdots + l_r = l \\ l_1 \leq n_1, \cdots , l_r \leq n_r}} T_{n_1,l_1} \cdots T_{n_r, l_r}$$$

where $C \left( n_1, \cdots , n_r \right)$ is the function that counts the number of partitions of $$${ 1,\cdots,n_1+\cdots+n_r+1 }$$$ into sets of sizes $$$1,n_1,n_2,...,n_r$$$ respectively (For example $$$C(2,1) = \frac{4!}{2!1!} = 12$$$ and $$$C(2,2) = \frac{5!}{2!2!2!} = 15$$$). In terms of generating functions, this becomes

$$$t(x,y) = \frac{1}{2} \int{e^{t(r,s) - \frac{1}{2} r(1-s)} dr}$$$

Taking partial derivative w.r.t $x$, we get

$$$\frac{\partial(e^{-t(x,y)})}{\partial x} = \frac{1}{2} e^{-\frac{1}{2}x(1-y)}$$$

Integrating w.r.t $$$x$$$, we get

$$$t(x,y) = -\ln\left( c(y) - \frac{e^{-\frac{1}{2}x(1-y)}}{1-y} \right)$$$

Comparing coefficients of $x^0 y^m$ on both sides for all $$$m \geq 0$$$, we have that $$$c(y) = \frac{y}{1-y}$$$. Thus for $$$n \geq 1$$$, we have that

$$$[x^n \cdot y^l]t(x,y) = [x^n \cdot y^l] \{ -ln\left(1 - \frac{e^{-\frac{1}{2}x(1-y)}}{y}\right) \} = [x^n \cdot y^l] \{\sum_{m=1}^{\infty} \frac{1}{m} \frac{e^{-\frac{m}{2}x(1-y)}}{y^m}\}$$$

Expanding this further, we get

$$$[x^n\cdot y^l] \{ \sum_{m=0}^{\infty} \sum_{r=0}^{\infty} \frac{1}{m} \frac{(-1)^rm^r}{2^r\cdot r!} x^r (1-y)^r \frac{1}{y^m} \}$$$

We must have $r=n$ and $$$r-m=l$$$ to get the required coefficient. Substituting this we get

$$$\sum_{m=0}^{\infty} m^{n-1} \frac{(-1)^n}{2^n\ n!} \binom{n}{m+l} (-1)^{m+l} = \frac{(-1)^{n+l}}{2^n \ n!} \sum_{m=0}^{\infty} (-1)^m m^{n-1} \binom{n}{m+l}$$$

Taking $$$k = n-m-l$$$, we can re-write the summation as follows

$$$\frac{(-1)^{n+l}}{2^n \ n!} \sum_{k=0}^{n-l} (-1)^{n-l-k} {n-l-k}^{n-1} \binom{n}{k} = \frac{1}{2^n \ n!} A(n-1,n-l-1) = \frac{1}{2^n \ n!} A(n-1, l-1)$$$

Now, since the coefficient in $$$t(x,y)$$$ is equal to $$$\frac{T_{n,l}}{(2n)! \ (n)!}$$$, we have that

$$$T_{n,l} = \frac{(2n)!}{2^n} A(n-1,l-1)$$$

Now, since the root is fixed, we must divide by $n$ to get only labelled trees having $$$1$$$ as the root.

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

Is it possible to solve problem C if it is defined in 3D space instead of a 2D plane?

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

Am i missing some edge case or what do i need to optimize in this for B if(a>c) { sum=sum+(a-c); a=c; } if(b>d) sum=sum+a+(b-d);

This is wrong for test case 7 it says . Helpppp

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

https://mirror.codeforces.com/blog/the_explorer_adarsh

1

1

5 9 2 3

Output should be 3 instead of 11: 0 0 0 0 0 1 1 1 1 1 1 1 1 1 will get 0 0 1 1 1 1 1 1 0 0 0 1 1 1

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

    But we can't do if we have only one pile i mean the solution is based on the fact that there exists a pile that will fit the 0s and 1s removed from a certain pile.????

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

Problem B is annoying.
These are my solutions:
1. Without I/O optimization which got TLE on test 9: https://mirror.codeforces.com/contest/2122/submission/330519530
2. With I/O optimization it got succeeded. Link: https://mirror.codeforces.com/contest/2122/submission/330520090
Is this kind of behavior expected for problems or is it just too strict test cases?
This means that we always need to have the I/O improvements!

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

Can anybody help me with my solution in problem D.

I dont know why it is failing on test case 2.

Problem Link: https://mirror.codeforces.com/contest/2122/submission/331618437

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

for the question C can we come up with some solution which first involves pairing the coordinates which have diagonally opposite quadrants, since for them the manhattan distance will just be the absolute sum of each coordinate, so pairing 1st and 3rd quad , 2nd and 4th, but I am not sure about the leftovers after this is done, atmax there will be coordinates left in the 2 quadrants.

Also can someone explain the tutorial of C in a better way

»
9 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

I think problem C is well-designed.. seldom see such clear and beautiful solution, even compared with problems with complex data structures