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

Автор IgorI, история, 6 лет назад, перевод, По-русски

Спасибо за участие в раунде! Я надеюсь, что вам понравились задачи.

1474A - Загадка из будущего

Hint 1
Hint 2
Editorial
Solution

1474B - Различные делители

Hint 1
Hint 2
Hint 3
Editorial
Solution

1474C - Уничтожение массива

Hint 1
Hint 2
Hint 3
Hint 4
Editorial

1474D - Уборка

Hint 1
Hint 2
Hint 3
Hint 4
Editorial
Solution

1474E - Что это?

Hint 1
Hint 2
Hint 3
Hint 4
Editorial
Solution

1474F - 1 2 3 4 ...

Bonus
Editorial
Solution

Удачи в будущих контестах!

Разбор задач Codeforces Round 696 (Div. 2)
  • Проголосовать: нравится
  • +307
  • Проголосовать: не нравится

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

thanks for fast editorial

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

Hope I'll become Candidate master today without new year's magic ;)

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

Man!!! That was really quick! Nice hints and clear insight.

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

If negative numbers allowed in problem C, Is this problem still can be solved ?

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

Thanks!

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

Good contest, despite O(N^2LogN) not passing in java for C

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

I am not understanding why i am getting tle verdict in third problem. I think i am doing it in O(n2⋅logn) but i am wrong maybe . Here is a link to my submission https://codeforces.me/contest/1474/submission/104839937 I would be extremely glad if someone can point out the error.

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

There doesn't seem to be any hacking round, so When is the rating gonna be updated?

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

Very well written tutorial. While solving C using multiset; one needs to remember that erasing an element by value will delete all elements having same value. And it costs you time to debug it and to read online documents.

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

Problem 1474D - Cleaning. I supposed that, if we don't use the ability, the answer is "yes" if and only if the sum of numbers on odd positions is equal to the sum of numbers on even positions, and every number is not greater than the sum of it's neighbors. But the solution fails: 104836378. Is my idea wrong, or is it because of some mistake in the implementation? I wasn't able to find any couterexample(and the test on which it fails is unvisible) nor any formal proof. Thanks in advance.

UPD: I have found the counterexample. Very weird my solution passed all those millions of tests.

1
8
2 2 4 3 1 2 1 1
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I was only able to solve A and couldn't finish debugging C. Just found out that the only bug in my C code was m.find(t)--. (It should be m[t]--)

-99 rating. YAY never been happier

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

I don't really understand the explanation for D. Can somebody explain/give an example for how p_i and s_i are calculated, and what the check mentioned in the last paragraph is? A link to a solution that implements this method would be just as good as well.

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

My Java Solution for Problem C: 104839108
Isn't it O(n^2logn) ? I used to HashMap.

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

in 1 sec per test: will our code of O(n^2) passes? if 1<=t<=1000 and 1<=n<=1000 because i read only 10^7 operations will pass... but here (n^2)*t will be around 10^9 right.. any clarification on this will be appreciated...

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

This editorial is awesome as it totally focuses on concepts instead of spoon-feeding.

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

It's hard for me to understand why there is only one way to make all numbers equal to 0 in problem D. I don't get how proof works. Can someone explain ?

»
6 лет назад, скрыть # |
← Rev. 4  
Проголосовать: нравится +55 Проголосовать: не нравится

My soln of F is similar to the model soln mentioned in the editorial of 1295F - Good Contest.

Firstly in linear time, we can compute the length of LIS.
Let's fix a minimum element of LIS say X and length by L. Then we know that LIS is $$$X,X+1,..,X+L-1$$$. We will loop over all possible Xs.

dp[0][X-1]=1.
dp[i][j] is no of LIS starting at X and end at j using first $$$d_1,d_2,...,d_i$$$
This soln works in $$$O(n*(max(Pi)-min(Pi))$$$.
One can refer to this Bruteforce soln for more details about DP states.

Soln in one line — dp[i] is a piecewise polynomial function of degree atmax i in j.

Let's denote B be the set of all values in prefix sum of the given array in increasing order.
Important thing to note here is there exsists a polynomial P(x) of degree less than or equal to i such $$$P(B_l)=dp[i][B_l],P(B_l+1)=dp[i][B_l+1],...,P(B_{l+1}-1)=dp[i][B_{l+1}-1]$$$.
So instead of maintaining $$$O(B_{l+1}-Bl)$$$ states we can just maintain i+1 values and interpolate this polynomial whenever required.

Also, X belongs to B.
For each polynomial, we maintain O(n) values. Interpolation takes O(n). There are $$$O(n*n)$$$ polynomials for each $$$X$$$.
This soln works in $$$O(n^4)$$$.
AC Submission

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

I just added solutions in C++ to all problems.

There are some problems with spoilers now, so hints are published without any spoilers (actually it is the reason editorial wasn't pusblished just after the contest).

Anyway, thanks again for taking part in my contest and discussing its problems.

UPD: Now hints should be ok

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

Hey, can someone explain why am I getting time limit exceed for problem C : https://codeforces.me/contest/1474/submission/104834766

I used a O(n^2log(n)) solution, normally it should pass..

I used an unerdored map in the last seconds and got accepted in 982 ms.

Thanks in advance

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

Can someone tell me Time complexity of my code , I think it is O(N^2) approx. https://codeforces.me/contest/1474/submission/104834839

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

Here are my video solutions of this round for A-E, which I'm really glad I didn't do a screencast for

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

Can someone explain why we don't need to check the case where $$$a = p^3$$$ in problem B ?

In other words why can't a solution be of the form: $$$1$$$ $$$p$$$ $$$p^2$$$ $$$p^3$$$ ?

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

    $$$p_1.p_2 \lt p_1^3$$$ where $$$p_1 \gt d, p_2 \geq p_1 + d.$$$ Since, we're asked to find the minimum integer $$$x$$$. Maybe, It's also because prime numbers are dense at the start.

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

      what if $$$p_1^2 \lt p_2$$$ ? or that just never happens due to the limits of this problem ?

      $$$p_1^2$$$ being greater or equal than $$$p_1 + d$$$

      $$$p_2$$$ being next prime greater or equal than $$$p_1 + d$$$

      any formal or convincing proof that this never happens?

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

        Bertrand's postulate, proven in 1852, states that there is always a prime number between k and 2k, so in particular $$$p_{n+1} \lt 2p_n$$$.

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

        As pointed in above comments , we can prove using Bertrand Postulate .

        More formally suppose you say answer is $$$p^3$$$ and thus it's factors are $$$1,p,p^2,p^3$$$ . Difference between each of them should be greater than $$$d$$$. Thus $$$p_1≤p$$$ . Using Bertrand Postulate we can say that there must exist prime $$$p_2$$$ such that $$$p \lt p_2 \lt p^2$$$ , since smallest prime is 2. Hence $$$p_1*p_2$$$ is better answer.

        You asked very good question , I never thought of it during the contest.

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

          No, I don't think $$$p_1^2 \lt p_2$$$ since $$$2p_1 \lt p_1^2, \forall p \gt 2$$$.

          We can further postulate that, there also exist a prime, $$$p_x$$$ that is less than $$$4p_n$$$ with Bertrand's Postulate since, $$$p_{n + 1}$$$ may not be greater than or equal to $$$p_n + d$$$.

          Thus, We can prove that $$$p_n . p_x \lt p_n^3$$$.

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

            I wrote $$$p \lt p_2$$$ .It's called proof by contradiction. So i assumed that $$$p^3$$$ is the best answer but then we arrived at contradiction that a better answer would exist in that case.

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

              Using Bertrand Postulate we can say that there must exist prime $$$p_2$$$ such that $$$p^2 \lt p_2 \lt p^3$$$.

              I don't know if this is called proof by contradiction. It'd be correct if you change the order as $$$p_2 \lt p^2 \lt p^3$$$ according to Bertrand Postulate.

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

                In Bertrand Postulate , take $$$n=p$$$ , also $$$p≥2$$$ , thus there must exist prime $$$p_2$$$ such that $$$n \lt p_2 \lt 2n≤p^2$$$. So how my argument wrong ?

                Thus we have better answer $$$p_1*p_2$$$ but that's contradiction since best answer was $$$p^3$$$ . Hence our assumption that $$$p^3$$$ will be best answer was wrong . Thus answer must be of form $$$p_1*p_2$$$.

                proof by contradiction . In this to disprove something we first assume it's correct and then arrive at some contradiction . Here i assumed $$$p^3$$$ is correct and then we arrived at contradiction .

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

                  In Bertrand Postulate , take $$$n=p^2$$$ , also $$$p\geq2$$$ , thus there must exist prime $$$p_2$$$ such that $$$n \lt p_2 \lt 2n≤p^3$$$.

                  I get what you're saying. But $$$p^2$$$ has to be a prime number in order to use Bertrand's postulate.

                  proof by contradiction. In this to disprove something we first assume it's correct and then arrive at some contradiction . Here i assumed $$$p^3$$$ is correct and then we arrived at contradiction.

                  Thank You, I didn't read about this before.

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

                  It can be any integer .

                  I get what you're saying. But $$$p^2$$$ has to be a prime number in order to use Bertrand's postulate

                  read here :

                  A less restrictive formulation is: for every $$$n \gt 1$$$ there is always at least one prime p such that $$$n \lt p \lt 2*n$$$
        • »
          »
          »
          »
          »
          6 лет назад, скрыть # ^ |
          ← Rev. 7  
          Проголосовать: нравится +3 Проголосовать: не нравится

          When you said p ^ 2 < p2 < p ^ 3, didnt you actually prove p1 * p2 is a worse answer? Because suppose p1 = p so then p1 * p2 > p * p ^ 2, because p2 > p ^ 2. So optimal would be p ^ 3.

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

This "Hint by Hint" format is nice. Keep it up.

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

I would be very thankful if someone can find the bug in my code https://codeforces.me/contest/1474/submission/104847038 I'm unable to figure it out

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

Problem B can be solved with help of regexes, as N is not big. Try it yourself.

Spoiler 1
Spoiler 2
Spoiler 3

Solution 104855574

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

The time constraints for C are absolutely atrocious, I tried 3 different n^2 log n implementation and I wasn't able to make any of them pass

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

If anyone is stuck at C https://youtu.be/Y_53vVG7RMw

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

I still have a question about prob D, why we just talk about the swap between 'a[i]' & 'a[i+1]' ?

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

My solution is getting WA on test 2 and I don't understand why. Can someone please give me a test case where this fails?

https://codeforces.me/contest/1474/submission/104864709

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

I got a few doubts in n* +max(a) solution of c

if (cnt[a[j]] < 0 || cnt[x - a[j]] < 0)
            {
                cnt[a[j]] = 0;
                cnt[x - a[j]] = 0;
                break;
            }

when the cnt of a[j] will be less than zero ? as for in while loop we check that cnt[a[j]]>0 also if i comment it out, then why it gives wrong answer since in reset(a) after ops, we are anyway setting cnt[a[i]] to zero ?

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

brilliant idea for problem D

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

Is +460 in first codeforces contest good? What is the metric for good and bad for codeforces contests?

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

This format of multiple hints and then answering them is great

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

Problem D, Now we have 0 stones in the 1-st pile and a2−a1 stones in the 2-nd pile. I understood this.

We can apply the idea above and get that we should have a2−a1 stones in the 3-rd pile. How do we get a2-a1 for 3-rd pile?

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

Why I'm getting RE in Case 6 in problem C, Help me (O_O) :

104870245

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

What's wrong with my D? I'm confused. 104868453

I'm not good at English..Emm...

If I don't use the superability,it will be ``` b[1]=a[1] b[2]=a[2]-a[1] b[3]=a[3]-a[2]+a[1] ... b[n]=a[n]-a[n-1]+a[n-2]-...

For odd numbers : b[n]=a[n]-a[n-1]+a[n-2]-...-a[2]+a[1] For even numbers : b[n]=a[n]-a[n-1]+a[n-2]-...+a[2]-a[1]

if we swap(a[pos],a[pos]+1]) b[pos] will -a[pos]+a[pos+1]

for i>=pos+1 i%2=(pos+1)%2: b[i] will -2*a[pos+1]+2*a[pos] i%2=(pos+2)%2: b[i] will +2*a[pos+1]-2*a[pos]

I want b[n]->0 and all i in [1,n] b[i]>=0 I calculate suffix(suf) and prefix(pre) ``` Oh,I can't make it any clearer,I'm poor in English...

upd: Accepted

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    If I don't use the superability,it will be
    b[1]=a[1]
    b[2]=a[2]-a[1]
    b[3]=a[3]-a[2]+a[1]
    ...
    b[n]=a[n]-a[n-1]+a[n-2]-...
     
    
    For odd numbers  : b[n]=a[n]-a[n-1]+a[n-2]-...-a[2]+a[1]
    For even numbers : b[n]=a[n]-a[n-1]+a[n-2]-...+a[2]-a[1]
     
    if we swap(a[pos],a[pos]+1])
    b[pos] will -a[pos]+a[pos+1]
    
    for i>=pos+1
    i%2=(pos+1)%2: b[i] will -2*a[pos+1]+2*a[pos]
    i%2=(pos+2)%2: b[i] will +2*a[pos+1]-2*a[pos]
     
    I want b[n]->0 and all i in [1,n] b[i]>=0 
    I calculate suffix(suf) and prefix(pre)
    
    Oh,I can't make it any clearer,I'm poor in English...
    
»
6 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

C was just awesome.

I solved it using the idea that at each operation we have to select two numbers among which one is always the maximum number among the remaining non selected numbers and the other number can be any number among non selected numbers such that sum of both numbers is equal to x(and then update x and repeat the process) If we can not do it for any selected x then answer will be No. And initial x can be (maximum of all numbers+ any other number from array).

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

Hello , Thanks for this awesome contest and awesome solution for Problem D.

However I tried to solve D using segment trees and I am able to get AC on it. What I am doing is creating two array for odd and even position and trying every swap by making appropriate updates and then rolling back to original states. I could'nt see anything wrong in my solution. Can someone help me figure it out ?

My code

Update: Figured out my bug, I skipped the fact that I had to update previous element also. xd

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

104885466 why i am getting tle

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

for some reason i feel tired of constructive problem.i dont hate them but while doing them i just feel so weird and solution often suprised very hard (like an unexpectd slap)

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

I advise everyone to watch this video, hope would be helpful!

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

Can we solve problem D if we are allowed to swap any two piles once? It could be a variation for this problem.

Suggesions are much appreciated.

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

If someone pls could help ! their solution for C without set ..isn't it O(n³) ? if not then why coz the three loops in worst case are gonna iterate and complete to their limit ?

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

Can anyone tell what is wrong in my D? WA on test 2: 105030694

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

Still stuck in problem D, can anyone help me? :| thanks. 105049987

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

somebody please explain why this is giving TLE for problem 1. https://codeforces.me/contest/1474/submission/104916660 again for problem 1, the following code prints all digits as 1, i cant see why it is happening https://codeforces.me/problemset/submission/1474/105175403

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

Hints for problems is such a great idea! I believe that hints+editorial is way better because some people may need just a bit of help to upsolve. Setters, please, make hints+editorial.

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

My $$$O(N^2)$$$ java sol for problem C is getting TLE. But such similar solution of others getting passed. Can anyone tell why it's getting TLE. I thought a lot but unable to figure it out. Anyone please.

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

For problem D,in case of no superability, why should we start from 0 ? why not from position n-1 ?

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

    It's basically simulation so you can start from either 0 or n-1. It won't have any effect on answers.I used basically simulation to solve like first simulating my code from index 0 to index k upto where it is possible to do this simulation. and similarly used same concept from n-1 to index k upto which simulation is possible. Now for checking swapping we take 4 indexs i-1,i,i+1,i+2. Now I first check that is value at i-1 by forward simulation and i+2 by backward simulation is it possible. If Both are okk.. When no swapping is done a[i]-pf[i-1]==a[i+1]-sf[i+2] When swapping is done a[i]-sf[i+2]==a[i+1]-pf[i-1] Pf and sf arrays are simulations values which we get by continuously subtracting from left and right repectively.

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

Problem B shows tag of binary search. How to do it using Binary search??

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

    Sorry For necroposting , But I just solved the problem and wanted to describe my solution.

    Hint 1
    Hint 2
    Hint 3
    Hint 4
    Hint 5
    Hint 6
    Hint 7
    Hint 8
    Complexity ?

    319490559