By awoo, history, 3 years ago, translation, In English

Hello Codeforces!

On Nov/22/2021 12:35 (Moscow time) Educational Codeforces Round 117 (Rated for Div. 2) will start.

The problems are based on the Southern Russia and Volga Cup 2021, which is a regional contest of ICPC. If you have participated in it or are planning to play it as a virtual contest, please refrain from taking part in the Educational Round.

Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.

This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.

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

The problems were invented and prepared by Adilbek adedalic Dalabaev, Vladimir vovuh Petrov, Ivan BledDest Androsov, Maksim Neon Mescheryakov, Roman Roms Glazov and me. Also huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.

Good luck to all the participants!

UPD: Editorial is out.

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

| Write comment?
»
3 years ago, # |
  Vote: I like it +25 Vote: I do not like it

NOTE THE UNUSUAL TIMING

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

eagerly waiting for the contest.

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

Why Unusual timing again? :(

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

Finally a cf contest after so long .....All the best to the fellow programmers !!

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

contest after long time in unusual time , why in the last period the contests in unusual time :(

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

On behalf of all Russian schoolers, I protest against the unusual timings on weekdays.

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

On behalf of myself I strongly support the unusual timing, it gives an opportunity for competitors around the world to participate :)

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

Will try to perform better this time. let's hope for the best. Good luck everyone!

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

Good luck everyone!

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

Last week one contest this week five contest I am not complaining, but it would have been better if contests evenly spaced them in these two weeks. Lately, there has been a lot of inconsistency in contests either there are very few, or there is a lot in a 7 to 10 days period. Anyway, today is contest day, so best of luck to everyone.

»
3 years ago, # |
  Vote: I like it -38 Vote: I do not like it

Can you change the timing i have meeting from 4:00 to 4:30 pm , please

»
3 years ago, # |
  Vote: I like it -12 Vote: I do not like it

Will the problems be arranged in the correct difficulty order? Or will it be shuffled as we see in icpc?

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

Mathforces

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

How to solve D?

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

How to solve E?

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

    i did it using ternary search on the number of messages to be pinned , and then selected the books in a greedy way, got tle on tc 149 , but after one optimization it ran comfortably. Update: the solution was wrong

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

      thx, got it

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

      Your function isn't parabola or convex. When T(len of answer) is [1; 20], ur function gets chaotic values. When T is [21; 2e5] fucntion decreases on all segment

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

      Your ternary search solution has been hacked :)

»
3 years ago, # |
  Vote: I like it -8 Vote: I do not like it

best contest i've ever done!

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

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

Does anyone know the proof for why it's never optimal to select more than 20 pins in 1612E - Messages??

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

    If $$$s_i$$$ is the sum of all $$$k_i$$$ with $$$m_i = i$$$, then the expected return you get from including $$$i$$$ is equal to $$$\frac{s_i}{t}$$$ if $$$t \geq 20$$$. Note that you greedily want to select the largest $$$t$$$ values of this for the messages, and you can show that this value is greatest when $$$t = 20$$$ (since averages decrease since you're taking lower and lower sums).

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

      I mean many people made the guess for first 20 but I wasn't smart enough ig.

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

    If you take 20 best messages out of $$$m$$$ taken in terms of expected value contribution and leave just them, their expected value will increase proportionally to $$$\frac{m}{20}$$$. But since they were maximal total EV will not decrease.

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

    Suppose we have selected the $$$y$$$ messages with the max $$$x$$$, where $$$y$$$ $$$\geq$$$ $$$20$$$, and $$$\sum{k_i}$$$ $$$=$$$ $$$x$$$ for all $$$i$$$ where $$$i$$$ is one of the chosen messages. If we select the $$$(y+1)_{th}$$$ message $$$msg$$$ where $$$\sum{k_j}$$$ $$$=$$$ $$$z$$$ for all $$$j$$$ where $$$m_j$$$ = $$$msg$$$, the first $$$y$$$ messages are still the best, and their total expected value decreased from $$$\frac{x}{y}$$$ to $$$\frac{x}{y+1}$$$, that is, decreased by $$$\frac{x/y}{y+1}$$$. However, $$$msg$$$ only introduced $$$\frac{z}{y+1}$$$, and $$$z$$$ $$$\leq$$$ $$$\frac{x}{y}$$$, otherwise it would be one of the best $$$y$$$ messages.

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

idk how many guys pass G, I want to say that F is much easier than G

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

    When I began solving G, it had 17 solves while F had like 3.

    Most people who reached F/G didn't have time to solve both, so it was probably just an observer effect here.

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

    Hi, can you please give some hints on how to solve F? For me G seemed easier than F.

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

      You can just optimize bfs.

      The queue contains tuples $$$(a, b, d)$$$ ($$$d$$$ is the number of moves to reach $$$(a, b)$$$). Let $$$(a, b, d)$$$ be a useless tuple if there exists a tuple $$$(a', b', d)$$$ in the queue, with $$$a' > a$$$ and $$$b' > b$$$. If you remove useless tuples from the queue (e.g. by rebuilding the whole queue if its size is $$$> 2 \cdot 10^5$$$), the bfs is fast enough.

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

How to solve D ? I called gcd(difference, maximum number % difference), but if the difference is larger, then it gets executed huge number of times...

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

    Basically, the numbers you can reach are everything reached by the Euclidean algorithm for a and b.

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

    I guess resultant number was eventually max-min*k such that max-min*k>=min after that max and min will change so you just have to check whether x%min==max%min otherwise pass for min,max%min

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

Hmm... I think G is easier than E. E was difficult to translate.

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

I dont know how total accepted submissions of problem D went from around 1200 to 1700 in last 20 minutes ;_;

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

traditional -100 for me kekw

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

EDIT: ok i got the mistake.

»
3 years ago, # |
  Vote: I like it -9 Vote: I do not like it

i should've been prepared more before joining this round

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

Can Anyone provide the intuition behind D, it ate up my whole hour, still couldn't find a logic.

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

    When assignment operations are only based on substraction of two no.s . Think GCD .

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

      i tried GCDs, but idk how to actually solve

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

        Go through the same procedure as GCD , and before recurring for GCD(b%a,a) check that whether (b%a)+(j*a) is equal to x or not , j is from 0->r such that (b%a)+((r+1)*a) is greater than b . For clearity refer this https://codeforces.net/contest/1612/submission/136448350

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

          Can you please explain this part? I would be very thankful to you.

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

            As I said before if x's value is b%a+(j*a) where j is 0 to r , then x is achievable . So x=(b%a)+(j*a) => x-(b%a)=j*a => (x-(b%a))%a=0 , as j*a%a=0

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

Should E really pass in $$$O(nlogn*20)$$$? I did write a solution which passes but with a high execution time. Can someone hack it?

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

Did anyone observed precision handling error in python in question 3

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

    Yes — do use from decimal import Decimal to handle floating point numbers with higher precision in Python.

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

What's the approach for E?

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

    Observation 1: if you're going to pick X messages, it's obviously optimal to choose the mi such that sum(min(ki,X)) is maximised (why? consider how you would write the expectation calculation as an equation). So the first thing we want to do is sort the messages by the sum of ki values assigned to that value of mi.

    Observation 2: it's never optimal to go beyond 20 messages (or, more specifically, max(ki) messages). Why? Suppose we have exactly max(ki) messages. Then our expected value is E20 = sum(ki)/20 for the users whose messages are in this set of 20. If we add another message, the expected value E21 = sum(ki_prev)/21 + sum(ki_21)/21 = E20*(20/21) + sum(ki_21)/21. Suppose E21 > E20. Then we have sum(ki_21)/21 > E20*(1/21) = sum(ki_prev)/(20*21), and hence sum(ki_21) > sum(ki_prev)/20. This means that the 21st message has a greater sum of ki values than the mean of the first 20. But this is impossible because the 21st message has a sum of ki values less than or equal to the first 20 values.

    So it's proven we will never go beyond 20 messages. Now we just try all possible values from 1 to 20, and find which gives the greatest expectation. There's a tricky nuance (which I believe I got wrong in contest) where you have to sort each time according to sum(min(ki,X)), rather than just sorting according to sum(ki).

    Code

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

      And you don't even have to make the second observation, I, for one, completely missed it. You can just sort all E20 highest to lowest and check all prefixes of this order.

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

      I Was looking for this proof precisely, Thank You for the clear explanation !

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

How to solve C?

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

Regarding this submission: https://codeforces.net/contest/1612/submission/136484148

If I'm not wrong, it's complexity is clearly $$$O(t * 10^6)$$$ for cases which results in -1 -1. So, it must exceed the given time limit easily (as $$$t \leq 3000$$$), but on Custom Invocation I have tried and it runs in $$$\sim 1500$$$ ms.

Can anyone kindly explain me why it is so?

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

How to solve F?

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

Can someone explain their approach to Problem D

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

What's the hack case on E?

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

Here are the video Solutions to the first 5 Problems In case you are interested.

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

Thanks for the good sample tests to avoid overflow in problem C.

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

Here's a heuristic solution for problem F: https://codeforces.net/contest/1612/submission/136557294

The idea is that it's generally much better to replace the smaller number to increase our power quickly (which greatly overpowers any gain from synergies), but for small values this might not be the best option. We take all possible choices for the first 6 moves, and then apply the following:

  • If $$$x$$$ or $$$y$$$ is already maximized, then replace the other.
  • If one of $$$x$$$ or $$$y$$$ can be maximized on the next move, then do that.
  • Otherwise, do whatever will increase power the most.

This passes all test cases but I highly doubt it is correct, and would welcome a valid hack.

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

To not keep you waiting, the ratings are updated preliminarily. In a few hours/days, I will remove cheaters and update the ratings again!

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

I panicked in this contest and lost a bunch of ratings. My biggest drop yet (-100). I couldn't even solve A. Is there anything I can do to get a better grip of my nerves in a contest and not panic when I see an implementation heavy or math problem in the contest?

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

164 pretests in E and still they do not have tc that fails the most obvious wrong solution)

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

What kind of time of sending tutorial is normal? Looking forward to the solution.QWQ

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

Auto comment: topic has been updated by awoo (previous revision, new revision, compare).

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

I received a System mail saying that my solution 136459207 matches with idkmyname_ submission 136471505. I believe this is because we both have used nor's publically available BigInt library
I had also put this link as a comment in my code, as one should do while copying third-party code. MikeMirzayanov please look into this

»
3 years ago, # |
Rev. 4   Vote: I like it -16 Vote: I do not like it

I got this email from Codeforces which says that my solution for problem C coincides with too many people.

It goes like- Attention!

Your solution 136470651 for the problem 1612C significantly coincides with solutions bihari_bandar/136430343, greyman/136431111, going-too-far/136431248, SnigdhaReddy27/136438434, Jee_none/136440961, loser53/136448455, Pratyush_tripathi/136449209, manishchembeti/136452512, yash112124/136453654, misra99/136456090, ashutoshtr/136458047, TheThinker_08/136458129, venom0912/136460586, Secret_Superstar12/136461961, pratik2912/136462123, shivam.yadav98939294/136462732, Karan10100/136462833, 123Alpha/136465897, crosscheck371/136466967, darkcoder_347/136470103, codeprakhar/136470651, ramanand_rv/136470925, noob_tusharb/136471502. Such a coincidence is a clear rules violation. Note that unintentional leakage is also a violation. For example, do not use ideone.com with the default settings (public access to your code). If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details. More information can be found at http://codeforces.net/blog/entry/8790. Such violation of the rules may be the reason for blocking your account or other penalties. In case of repeated violations, your account may be blocked.

Now, I don't understand how my solution can so perfectly coincide with so many people even when I don't know who they are! I even have never used Ideone.com.

I was previously trying to solve this question using simple maths(quadratic equation solution) but that didn't work so I thought of another method that involved simple binary search. It worked.

I understand that the code of binary search is freely available at almost any programming website which leads to this coincidence.

Codeforces community... How can I get this fixed?

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

    Please look into this matter MikeMirzayanov

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

    why does this kind of coincidences always happens to indians?

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

      At least compare my solution with others before demeaning India or its coders.

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

        yes

        you just changed the names of the variables

        just another dirty indian still lying after being caught

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

          Yes Sir It was my bad to argue with you. You are absolutely correct! :)

          Though your mind is still filthy like your DP.

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

            ohno i smell dead bodies!!

            did you took a bath in the Genzies river today?

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

              Haha Nothing like that exists

              Don't even know the names of rivers. Poor boy

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

MikeMirzayanov I got an email from the system that one of my solutions for this round coincides with many others. Although I still can't understand why it happened;

The main concern is that All the problems for this contest were skipped from evaluation but still, my rating went down by -108. If the contest was skipped; shouldn't the rating neither increase nor decrease?

Please look into it and return my rating like before this contest. Thank You

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

I want to ask question F, if I just think about q=0, does it have the same number of answers as it has the right answer? How long does it take for the Fibonacci number to form Max of m,n