Автор BledDest, 7 лет назад, перевод, По-русски

Привет, Codeforces!

Отличные новости! Harbour.Space поддержал возвращение образовательных раундов на Codeforces! Подробности можно прочитать в посте.

27 марта в 17:35 MSK начнётся Educational Codeforces Round 18.

Вам будет предложено 6 задач и 2 часа на их решение. Мы надеемся, что все, и новички, и опытные программисты, найдут для себя что-нибудь интересное в этом контесте. Контест будет нерейтинговым.

Раунд вместе со мной готовили Михаил awoo Пикляев и Михаил MikeMirzayanov Мирзаянов. Благодарим Максима HellKitsune Финютина и Алексея ashmelev Шмелёва за тестирование раунда.

Надеемся, контест вам понравится! Желаем удачи!

UPD: Разбор задач.

UPD2: Все успешные взломы добавлены в набор тестов, и все решения перетестированы на новом наборе. Спасибо за участие!

  • Проголосовать: нравится
  • +186
  • Проголосовать: не нравится

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

Can anyone confirm to me that this contest won't be rated, because im not sure

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

Unfortunately, it clashes with csacademy round 22.

»
7 лет назад, # |
  Проголосовать: нравится -135 Проголосовать: не нравится

MikeMirzayanov

** WHY TO ORGANIZE SUCH UNRATED CONTEST? IF ANYONE WANT TO LEARN HE CAN PARTICIPATE VIRTUALLY.AND IF ANYONE WANT TO SOLVE QUESTS LIKE THESE ROUNDS' THEN WE CAN USE TAG OF EDUCATIONAL ON PROBLEMS LIKE PTHER TAGS DS,DP ,GRAPHS ETC.SO,THERE IS NOTHING IN FAVOUR OF THESE KIND OF UNRATED ROUNDS**

»
7 лет назад, # |
  Проголосовать: нравится -19 Проголосовать: не нравится

Making educational round be rated, the number of participant will increase a lot. Sorry for my poor English.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +16 Проголосовать: не нравится

    I see a lot of people apologizing for their English here. Why ? It is not like English is your first language. Chill man.

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

      Generally speaking, only 25% of world population speaks English, rest of the people use google translate and add "Sorry for my poor English" at the end.:-D

      Sorry for my poor English.

»
7 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

Thank you Harbour.Space for Supporting........

»
7 лет назад, # |
  Проголосовать: нравится -22 Проголосовать: не нравится

IS IT RATED!!?!?!?!?!?

»
7 лет назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

It's interesting that some of my friends are more interested in participating when it's not rated haha

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

The issue with problem C may have affected some contestants. The round should be unrated.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +94 Проголосовать: не нравится

    Yay. I totally agree with you :)

    The organizer must have predicted this issue would happen and announced the round to be unrated before the round had started.

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

E is so beautiful and amazing! Thank you!

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

Did someone else keep getting WA15 on F? If yes how did he/she fix it?

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

isn't E a binary search? get WA at test4!

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

Will the test data be published now or one day later?

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

Has "unused" hacked his own solution ?! Appears so to me !!

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

Is F relative to Linear Programming? Using duality lead the problem to work with lines.

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

    i am not sure but i guess maintain an upper convex hull of points and checking if the query points are inside or not should work , something like this.

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

    It can be solved with geometry, we have to support two operations:

    1. add one point (mana cost, damage) and keep the convex hull of all the points so far.

    2. determine if after scaling the convex hull by t it intersects the rectangle (Maximum mana, Health)

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

What does "unexpected verdict" mean when hacking a solution? I received it while hacking problem C.

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится +4 Проголосовать: не нравится

I tried to hack C and the verdict was "Unexpected verdict". What does it mean?

**UPD**: It is now a successful hacking attempt
»
7 лет назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

Why do I get Unexpected Verdict while hacking C?

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

What was the expected complexity of problem E?I guess I had a solution in nsqrt(max(ai)).

»
7 лет назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

I hacked a friend on a solution he sent after the contest finished but still got -1 on hacks. Is this intended?

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

Why so many people hacking their own solution?

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

Great contest! Are editorials for the problems going to be published? And when?

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

How to solve D?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +9 Проголосовать: не нравится

    notice that all values in left subtree < value at current node and all values in right subtree > current node and all values in this subtree are in some range [l , r] and the value at current node is (l + r) / 2. Using this you can find the node u in log(N) the same way as you find stuff in a binary search tree and then continue the traversal there while mainting the list of ancestors of a node.

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

      I did that solution during the contest, but i keep getting WA on test 10, do you have an idea why that happens 25855671

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится +1 Проголосовать: не нравится

        I also got a WA on test 10, then I removed all the pow() operations and computed the values on my own, and this got me an AC. I think it's due to the inaccuracy of pow(), that you are getting a WA.

        • »
          »
          »
          »
          »
          7 лет назад, # ^ |
          Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

          Yup, the problem turned out to be bitwise operations, i simply changed the line root=1<<(levels-1); to root=(n+1)/2 and it got accepted.

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

            It should be 1LL << (levels - 1) — shift amount doesn't promote the type of expression to long long.

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

              ohh so that was the problem. Thank you ^^ I will keep that in mind from now on

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

      Can you explain the proof of the fact that the value of the current node is $$$(l+r)/2$$$? I think it is very easy to come up with this observation but I can't seem to prove it.

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

    I used two variables l and r to mark the leftmost (smallest) number and rightmost (largest) number of the subtree of current node.

    For 'L' and 'R' operations:

    When l = r, it means that the current node is at the deepest layer, so we should ignore these operations. Otherwise, shrink the range by making l = mid+1 for 'R' operations, or r = mid-1 for 'L' operations, where mid = (l+r)/2 (the current node).

    For 'U' operations:

    When l = 1 and r = n, it means that the current node is the root, and we should ignore this operation. Otherwise, check the (x+1)th bit where xth bit is the lowest bit containing 1. If that bit is 1, the current node is in the right subtree of its parent. If that bit is 0, the current node is in the left subtree of its parent. Expand the range by moving l and r pointers.

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

    I made a function that receives a number x and returns info = {value, level, left/right, difference with parent} about it in log(n).
    You can observe that for node x, value of left child is x-dif, value of right child is x+dif. dif reduces by 2 on each level.
    Using this, it becomes easy to process up, left and right queries.
    Here is AC code.
    Here is same code with comments.

»
7 лет назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

How do you solve E?

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
    1. Let the number of ball in box noted a1 a2 ... an;
    2. First you will find the minimum ai in this array (marked as ak).
    3. Then, let's enumerate all size as (ak/1, ak/2, ... ak/ak), let pki = ak/i, if (ak%i == 0) we will try that (pki, pki+1) and (pki, pki-1), otherwise, we wil try (pki, pki+1);
    4. If we discover a pair (pkj, pkj+1) can combinate all box(a1,a2,...an), then we find the maximum size of set is (pkj, pkj+1);
    5. Output the sum of Pi = ai/(pkj+1) (PS: if (ai%(pkj+1)) != 0 then Pi = Pi + 1) for answer.
    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      And here is my poor code... I'm sorry about I forgot it.25873907

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

      Why we are treating the case when a[0]%k==0 differently?

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

        If ak%i == 0 then we don't know if (pki,pki+1) can combinate all box, If it can make it, they will be the maximum size. If not, then(pki-1,pki) also can combinate this box ak, so I think we should try this case.

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

How do I solve C?

  • »
    »
    7 лет назад, # ^ |
    Rev. 4   Проголосовать: нравится +3 Проголосовать: не нравится

    Find K = sum%3. If its 0, you are done.
    Otherwise, you have to remove at max 2 elements to make it a multiple of 3.
    So there are few cases only that you have. I maintained a vector of pair for both cases, when K is 0 and when its 1. Find for each case the resultant string and take the one with minimum deletions. (Also for more optimization you won't remove digits like 3,6,9 anyway.) Here is the code.

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

How to solve C ? Is this a greedy problem ?

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

What is wrong with this approach of D ?

IF str[i] = 'R' do curr_node = curr_node + 2^(tree_height-curr_height -1 ).

IF str[i] = 'L' do curr_node = curr_node - 2^(tree_height-curr_height -1 ).

IF str[i] = 'U' , I divide curr_node by 2 until it becomes an odd number. If obtained_number+1 is divisible by 4, this implies curr_node is right child of it's parent. currr_node = curr_node - 2^(tree_height-curr_height).

Else currr_node = curr_node + 2^(tree_height-curr_height).

I am maintaing curr_height accordingly at each step and also checking for the bounds.

Getting WA at test case 6.

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

    I think the method you decide if a node is a left child or right child is wrong, because everything else that you said is like mine solution. Instead of checking if current_node is a right child or left child by some formula, I simply keep a stack on the moves I have made. You can look at my solution if you want 25872554

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

      Actually, the solution worked.

      I had error in implementation. The algorithm is passing all the test cases.

      My AC Solution: Link

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

When are the editorials scheduled?

»
7 лет назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится
»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

the problem C's datas are too strong,,,I had WA many times.

»
7 лет назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

Someone pls help me with this. this program runs pretty well on my own computer. But it does not work in the test. It got wa on test 3, where the output should be all YES (and it is on my computer)

25863026

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +9 Проголосовать: не нравится

for problem A, there are more than 150 hacks in java.what's wrong with java ?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +9 Проголосовать: не нравится

    In problem A, Anti-quicksort hack cases work.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    Java has a method called Arrays.sort(); that uses a quick sort method to sort an array. Quick sort's average run time is O(nlogn), but it's worst case scenario sort is O(n^2). People used a worst case scenario input/generator to hack many java solutions.

    P.S. To fix this just use Integer instead of int for your array since to sort objects, java uses a merge sort instead, which runs in time.

»
7 лет назад, # |
  Проголосовать: нравится +22 Проголосовать: не нравится

Один из лучших образовательных раундов, благодаря нему можно увидеть насколько плохо работает Arrays.sort в некоторых случаях :D.

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

Вот и сам взлом из 2015 http://codeforces.com/contest/101/submission/3882807

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

Could someone please explain this to me: In problem E, I used the solution to go from i to min in array a, and then check min/i and min/i + 1... I understand why and why we check these things ( for every element in a, x1 = a[j]/x, mod = a[j]%x, and if(!mod) just add x to ans, if not, check if(x1+mod<=x-1) add x+1... otherwise... return 0, it's not possible for this x). Now, my question is, is there a proof why this never exceeds the time limit (in fact, it doesn't seem to even get close to exceeding it)? Because the smallest element can be larger than 10^8?

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    We don't iterate from i = 1 to , instead it's up to . When you want to divide some ai into k sets, each set will be of size . Therefore or . Thus, it's possible to check every case by checking up to the root. Since on each iteration we iterate over our array of size n, the time complexity of the solution is

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

      Thanks for your time, I get that but I submitted a code which goes until m and breaks when a correct solution is found. But I only check m/i and m/i+1, whereas for it to mathematically be correct, I have to check for i+1 and i as well, however I don't and it still works, what am I missing? Edit: This is my submission (28747357)