vovuh's blog

By vovuh, history, 5 years ago, translation, In English

UPD: The editorial is published!

<almost-copy-pasted-part>

Hello! Codeforces Round 598 (Div. 3) will start at Nov/04/2019 16:15 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

  • take part in at least two rated rounds (and solve at least one problem in each of them),
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round.

Good luck!

I also would like to say that participants who will submit wrong solutions on purpose and hack them afterwards (example) will not be shown in the hacking leaders table.

</almost-copy-pasted-part>

  • Vote: I like it
  • +157
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

thank you for holding a div3 contest!!

»
5 years ago, # |
  Vote: I like it +6 Vote: I do not like it
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to register unofficially ? I clicked on register, but it only allows for ratings less than 1600.

  • »
    »
    5 years ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    You get a big ugly warning message that you will be registering "out of competition" (i.e. unrated), but you should still be able to click past the agreement and then solve the problems during contest time

  • »
    »
    5 years ago, # ^ |
      Vote: I like it -8 Vote: I do not like it

    solve question ...you will be registered unofficially !!

»
5 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Imagine vovuh were a super cool meme-lord...then these posts would have had dope memes after the closing bracket and everyone would have literally waited for every Div 3 announcement holding their breath...

»
5 years ago, # |
Rev. 2   Vote: I like it -13 Vote: I do not like it

Nice time.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

A person with a rating of 1599 can enter the competition but a person with a rating of 1600 cannot This makes the second person fall far behind

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

this is my first out of competition contest :)))

»
5 years ago, # |
Rev. 2   Vote: I like it -8 Vote: I do not like it

Hope it to be like previous div2 597 round contest That was really amazing....

»
5 years ago, # |
  Vote: I like it +7 Vote: I do not like it

i need only 3 points to be pupil ..please

»
5 years ago, # |
Rev. 2   Vote: I like it -19 Vote: I do not like it

dislike it if yo wanna lose ur rating

»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

10 minutes delay returns

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Delayed :/

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I look forward to glory and honor. The competition may begin.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    My worst contest ever. :/

    I should have solved all, but did fiddling on B for like two hours. Really loosing the fun of this.

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

delay 10m?

»
5 years ago, # |
Rev. 2   Vote: I like it -20 Vote: I do not like it

deleted

»
5 years ago, # |
  Vote: I like it -29 Vote: I do not like it

this was unbalanced one ..

  • »
    »
    5 years ago, # ^ |
    Rev. 3   Vote: I like it +23 Vote: I do not like it

    no it was, you think like that only beacuse you did just two problems. Problems were really good!

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

    If you swap D and C it's actually relatively balanced, maybe the difficulty between A and B is a bit too wide though.

»
5 years ago, # |
  Vote: I like it +15 Vote: I do not like it

I like that contest.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

here's no system testing?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    No, in div3 and educational contests tests aren't divided into pretests and tests and there are no hacks during the contest time, so your code runs on all the tests during the contest. After that there's a 12hr hacking phase before the final results are announced.

»
5 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Does anyone know why a runtime error may occur on 15th test in problem D?

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

How to solve F?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +42 Vote: I do not like it

    If the strings don't have the same letters, answer NO. If some letter appears at least twice, you can swap those two letters to be adjacent, then swap them in the first string and make an arbitrary swap in the second string, therefore we can answer YES. Now assume duplicate letters don't appear, and consider the strings as permutations.

    You can do any even number of swaps of adjacent elements to one string without changing the other. Also, every inversion of some intervals either doesn't change the parity of the permutations or changes the parity of both permutations. If the parities are equal, we can make the strings equal with an even amount of swaps, therefore we answer YES. If they are not equal, they cannot be made equal, and therefore we answer NO.

    Code: 64228071

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Do you calculate parity in O(n^2) ?

      • »
        »
        »
        »
        5 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        You can do bubble sort and count how many swaps you make or check for every number how many numbers are higher to the left.

      • »
        »
        »
        »
        5 years ago, # ^ |
        Rev. 2   Vote: I like it +1 Vote: I do not like it

        parity function will check parity of strings if there is no repeated character. That means length of strings should be less than 26 .It is simple pigeonhole principal

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          lol thanx! I did not get that it is only 26 =)

      • »
        »
        »
        »
        5 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        Number of adjacent swaps can also be calculated in O(NlogN). Although it is not needed here since in that case we have N<=26.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      "Every inversion of some intervals either doesn't change the parity of the permutations or changes the parity of both permutations."

      How to prove this ? Which permutation is being selected in both of the strings ?

      • »
        »
        »
        »
        5 years ago, # ^ |
        Rev. 3   Vote: I like it +3 Vote: I do not like it

        Consider any segment $$$T$$$ of a string $$$S$$$.

        There are $$$3$$$ types of inversions

        1. Both characters in $$$S$$$
        2. One in $$$S$$$ and one in $$$T$$$
        3. Both characters in $$$T$$$

        Only type $$$2$$$ is affected by reversing a segment.

        If the length of the segment is $$$L$$$ and there are $$$x$$$ inversions, the number of inversions becomes $$$L(L — 1)/2 — x$$$

        If the first term is even, the parity remains the same.

        Otherwise, the parity flips.

        Amazingly, the parity flips based on the length of the chosen segment and not at all on the permutation we use :).

        This is a mind-blowing fact :)

        Here are my solutions to this contest and here is my detailed editorial :)

»
5 years ago, # |
  Vote: I like it -14 Vote: I do not like it

Hello div2! Is that you ?

»
5 years ago, # |
Rev. 2   Vote: I like it +18 Vote: I do not like it

B, C & D are easy to come up with the idea, but the implementation is not trivial, I don't like these kind of problems.

»
5 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

I submitted problem C with MS Visual 2017 compiler (I use Visual Studio 2017), and it gave me WA on the 2nd test case while it's working on my computer and on GNU compiler, I got AC with the same code after the contest.

with MS C++ 2017

with GNU C++ 2017

So I think something is wrong with MS C++ 2017 compiler.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    You might be doing something that's undefined behavior

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Yep, undefined behavior

    Clang++17 Diagnostics says: p71.cpp:12:7: runtime error: index -1 out of bounds for type 'int [1001]' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior p71.cpp:12:7

    In a[qan - 1] when qan is 0

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Is a solvable with binary search?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Ternary search if you want

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It can be solved in O(1) time. 64209894

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Binary search on the number of coins of value n. So lower_limit = 0, upper_limit = a

    if mid*n > total then upper_limit = mid — 1

    else find the number of coins of value 1 (total-mid*n). If this value is <= b then "YES" else lower_limit = mid + 1

    Code : 64218027

»
5 years ago, # |
  Vote: I like it +27 Vote: I do not like it

MikeMirzayanov Just a little suggestion from me, could you add contest timer in m1 / m2 site during the contest?
I know that you can estimate the remaining time yourself, but it could be more convenience (at least for me) to see the timer directly. Thank you.

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

If you hack something, will this give you points?

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    No. Not for Div 3s and Educational Rounds where it is open hacking. But best hackers for opening hacking will be featured in the blog post.

»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Great Contest. Thanks for this round. Clear Statements! Keep up the good work.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    B to D, greedy. Not that standard. D could be harder.

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

I couldn't access codeforces last 20 minutes. Did anyone have a same problem? I confirmed some of Japanese contestant couldn't.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    use lightweight sites (m1.codeforces.com) (m1/m2/m3)

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    yeah. I faced this for half an hour.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Yeah, my fellow Indian contestants and I were also not able to access the contest, but it was accessible using m2.codeforces.com

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I accessed with m1.codeforces.com. But, you can't say the current standings.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Actually, I couldn't reach codeforces even the contest is end. but, I found that some of discussion was posted when we couldn't access codeforces. whats going on!?

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        That I didn't know before, I guess it must have been a problem for us Asians only.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    I had same problem and I thought this contest would be unrated. I tried to access another web site but unfortunately I forget my password. Zzz

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it
LOGIC OF A:- Check for largest multiple of n just below S and then check how many coins are required for it if(it is less than available coins then it is case 1:-
now 
m=((s/n)*n)/n;
    if(a>=m)
    {
       j=s-k;//final money left to pay after making payment with type n coins
    }
    else 
    {
        l=a*n;
        j=s-l;//final money left to pay after making payment with type n coins
    }
  Now final Answer is 
`    if(j>b)
       cout<<"NO\n";
       else 
       cout<<"YES\n";
    }`

Now for B the following is a big hint

Spoiler

Now FINAL D //C I DON'T TRIED

hint for D
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

greedy and greedy. C and D would have been more classical.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Some swapping problems! I like problem D.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve problem E. I can't get any idea.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +7 Vote: I do not like it

    Okay, My approach is , first of all sort the array. Now we have to split the array into such sub-segments that each segment is consists of at least 3 numbers. Now, Let our answer be ans. At first we can say that ans = arr[n-1]-arr[0] . Now for each valid splits in position i, we can improve our answer by arr[i]-arr[i+1] . we have to find a set of such i, that summation of all arr[i]-arr[i+1] is as lowest as possible. Let it be Sum . So , our final answer will be , ans= arr[n-1] — arr[0] + Sum . How do we find such Sum ? Just used dp on every i where i>=2 && n-i<=3

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    I did it like this-
    First sort the array
    Now the obervation is that each segment would of atleast length 3 and atmost length 5. It makes sense because if we have a segment of length 6 then we can split it into two segments of 3 and we are sure to get the smaller sum because the array is sorted.

    now we can use dp , here dp(i,j) is the min cost if we have a segment of length j ending on ith index. Of course only 3 values of j are possible.
    Since you could not get idea, I am not writing the complete equations and mentioning only the state. You can look at my solution if you want.

    ps: I hope this passes the sys tests too.

»
5 years ago, # |
  Vote: I like it +11 Vote: I do not like it

A very nice lexicographicallySmallestForces contest!

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Anyone please tell me what's wrong with my code 64271656 for problem B?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone please explain problem E dp state and transition

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +4 Vote: I do not like it

    First, Sort array $$$a$$$ in increasing order. Each team contains at least 3 members and you want to minimize the total diversity of all teams. So, there is no reason to build a team more than 5 members because you always can split the teams (>5 members) into smaller teams and reduce the diversity. Now, you can solve problem with DP technique in linear time.
    Let $$$dp(i)$$$ be the minimal total diversity of the school which consists of first $$$i$$$ members.
    Transition:

    $$$dp(i) = max \begin{cases}dp(i-3) + a[i] - a[i-2] \\dp(i-4) + a[i] - a[i-3] \\ dp(i-5) + a[i] - a[i-4]\end{cases}$$$

    Base case:

    • $dp[1] = dp[2] = Infinity$
    • $$$dp[3] = a[3] - a[1]$$$
    • $$$dp[4] = a[4] - a[1]$$$
    • $$$dp[5] = a[5] - a[1]$$$

    Run transition to calculate $$$dp[i]$$$ with $$$6 \leq i \leq n$$$.
    The answer is $$$dp[n]$$$. You can construct the configuration by yourself.

»
5 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

I can't find my mistake... where is "wrong answer each team should consist of at least three students"??? https://codeforces.me/contest/1256/submission/64279213

  • It was incorrect teamcount....
»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

In problem E, I came up with the solution using DP but I can't construct the configuration in time =)))

  • »
    »
    5 years ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    you can construct the configuration after getting the answer, by checking all the state from dp[n] to dp[1],details can be referred to my code.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thank you, I will check your solution.

»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Waiting for system test to become blue again...

Edit:FST on C..weak pretests..to be more careful next time..

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

In problem C I wrote p+d<n instead of p+d<=n and passed the pretests... Why so weak pretests?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

congrats. system testing is done

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I solved 4 questions in contest and 2 of them failed system testing ! Why are the pretests so weak !!! And that too for a Div3 round this is not how it should be, I understand that while coding one should consider all cases but shouldn't that be tested in Div2 then?

»
5 years ago, # |
  Vote: I like it +4 Vote: I do not like it

It's the first time I become Expert, I'm so happy now =)))

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

How could a O(n^2) solution passed for F? I don’t get it. Please someone explain it to me. TIA.

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    Well, if string has 2 or more equal letters in it, then the answer is YES. In other case the length of string is not more then 26

»
5 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

I have a doubt regarding the problem "Minimize the Permutation". My approach was that I iterate from 1 to n and try to bring the smaller elements(from 1 to n) forward, and do the same for next element if, I have either brought my current element(say i) to the 'i-1'th position or I could not swap it anymore(to bring to a lower index) for that I maintain a 'swapped' vector.

But, my solution didn't work because I didn't add the condition "arr[j-1]>arr[j]" for the while loop(i.e we have to swap only if the element on the left is bigger). And works fine if I add it. Can you please help me understand that why do we need to add this condition, is it not obvious? Can someone please explain to me with a small test case?

This doesn't work. This works.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yes bro , I have experienced same issue. Can anyone please explain the above with a small test case ?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    consider the case: 4 4 2 1 3

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      But that is not a valid permutation according to the question. Read it again.

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        the permutation is [4, 2, 1, 3]. The first 4 is the size, and my line-breaks were eaten. After the first iteration of the number 1 and number two, it is ok that the sequence turns to [1, 4, 2, 3]. In the second iteration, 2 will not be moved because there has been a swap in the first iteration. It gets into trouble when a new iteration of the number 3. 2 and 3 would be swapped if you do not compare them, and the result would be [1, 4, 3, 2].