Автор awoo, история, 2 года назад, По-русски

Привет, Codeforces!

В 31.01.2022 17:35 (Московское время) состоится Educational Codeforces Round 122 (рейтинговый для Div. 2).

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

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Адилбек adedalic Далабаев, Владимир vovuh Петров, Иван BledDest Андросов и Максим Neon Мещеряков. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

Удачи в раунде! Успешных решений!

UPD: Разбор опубликован.

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

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

Hoping for a great contest on Chinese New Year's Eve!

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

Hope this educational round completes without interruption.

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

Почему в телеграме неправильно указано время?

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

Good luck everyone!

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

Happy luner new year :3 hope this will be a good contest to say good bye this year :3

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

Good luck and high rating for everyone!

As a competitor in China, I'm quite happy to have something to do one New Year's Eve!

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

Hi, pls upvote I couldnt think of a smart comment this contest

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

Наконец-то я достоин своей аватарки

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

Hope for good luck.

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

Sad that last unrated educational round wasn't compensated with a rated one.
But hoping this one goes well, GL & HF.

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

Score distribution when?

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

Score distribution when?

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

    It will be held on extended ICPC rules. It's like div.3, contestants will be sorted by the number of solved problems,then penalties

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

      Either the questions were easy or I have been evolved from div 3, the contest was really confidence-boosting, thank you

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

Best of Luck everyone!!
May you not get WA at the very first problem. LOL

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

Happy Chinese New Year!

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

Is this contest, a negative point is given to every wrong submission? Or it is the penalty-based contest?

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

This is gonna be my first division 2 contest after getting my first rating on a division 3 contest. Contest means full of excitement and inspiration to make me a better version of myself. And hacking phase is awesome and breathtaking. Smile!

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

Do you know why the problem rating information is not shown for recent rounds' problems? (Codeforces Round 767 (Div. 2) and later)

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

all awoo's contsts are great

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

I always think that is we should solve problems from top to bottom or bottom to top? As I see lots of coders start solving problems from 2 or 3 questions

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

    As far as I know, out of all problems you solve finally, each minute you put a problem unsolved is counted as penalty.

    Suppose you solved 2 problems("A" and "B") in a contest:
    Let's assume "A" takes 10 min and "B" takes 20 min to solve.
    - Case 1 : You started with "A" and solved "A" after 10 minutes of the contest and "B" after 30 minutes of the contest. Penalty for these two is (10 + 30) = 40 minutes.
    - Case 2 : You started with "B" and solved "B" after 20 minutes of the contest and "B" after 30 minutes of the contest. Penalty for these two is (20 + 30) = 50 minutes.
    

    So it is good to start with problems that take less time to solve.

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

      yes, this is always optimal for educational and div 3 rounds which have same points for every problem.

      while for normal div2 rounds you may solve B or C first(depends on which you are comfortable) as they can provide you more points if you solve them first

      but still its not always the case that you will benefit every time. though i prefer to start from A

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

Hi. I am new here. Wish me luck !

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

Good Luck to all Coders ! ! ! awoo's contest are fantastic ! ! ! Never give up the CodeForces ! ! !

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

First time on joining any contest. I dont expect anything but to be better. Such a vibe

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

all chinese coder are giving a down vote it seems XD. happy new year to all chinese._|_

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

chuxi forces :)

happy lunar new year to those that celebrate!

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

Why in Problem D, sample hasn't been explained. :( T_T

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

Omg, it took me 10 minutes to solve the problem A, and 8 minutes to solve problems B and C together, cool

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

    It felt interesting to me, that in rated rounds I try to not even waste a single second, while you also take the time to announce your submit status xD.

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

Problem E looks interesting but it also seems to 100 Kms above my interesting interval ;_;

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

it was my first round ever and thankfully to authors it was pretty fun. Thanks!

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

solution for D?

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

    calculate the number of operations required to convert ai to bi and then knapsack.

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

      Did same but got Memory Limit Exceeded on Test 12. Value of k given is much larger than 1000 * (maximum steps required for any ai to convert to bi). Took k as minimum of k and steps*1000 after contest. Got AC ;-;

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

        There's a much tighter bound, use steps * 12. You can reach any number less than 1000 in less than or equal to 12 steps.

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

https://codeforces.com/contest/1633/submission/144748935 [TLE in test 12, problem D] How do i optimize the knapsack dp for choosing the indicies?

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

    Observe that if k is greater than sum of all operations we can skip knapdsack dp. And sum won't be too big.

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

    the maximum number of operation to obtain any number from 1 to 1000 using that operation is 12. So k can be at most 12*n. So if k > 12*n just make k = 12*n

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

      Thanks Eren and Liviu, got AC. Feeling stupid right now!

      Liviu how did you come up with "#ops to obtain any number 1 to 1000 using that operation is 12"?

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

        just printed the maximum element after the calculation was done. I needed that number to be small enough in order to not get TLE.

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

        In fact you can write another program to calculate this.

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

      How can I calculate the number of steps required to convert ai to bi?

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

        DP. You can calculate it for every number from 1 to 1000 cause b[i] <= 1000. Now you know that dp[1] = 0 cause a[1] = 1 already. And now make a for for each number 1 <= j <= i and let dp[i+i/j] = min(dp[i+i/j],dp[i]+1). This means take the minimum number of operation to reach the number (i+i/j) coming from i state (which is already calculated).

        Ex. you know dp[1] = 0 dp[2] = 1 dp[3] = 2 dp[4] = 2 dp[5] = 3 and you want to calculate dp[6].

        dp[6] = min(dp[3]+1,d[4]+1,dp[5]+1) since you can reach 6 for 3 adding 3/1 for 4 adding 4/2 and for 5 adding 5/3 or 5/4 or 5/5.

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

I used dynamic programming for D, can someone show me why it get WA? https://codeforces.com/contest/1633/submission/144729710

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

    Your DP state is incorrect. Use 01 Knapsack DP : Link

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

      I thought what I'm doing is 0-1 knapsack. I thought that looping in reverse order of the dp state (dp[i] = best total coins given total cost i), makes it so the element of the knapsack can't be re-used. Anyways thanks for the tip.

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

      I compared with the guy who got #1 and saw that my dp state and recursion are exactly the same as his (144679861). After looking at the case I failed on, it's because of this code

              int best_coin = 0;
              for (int i = 1; i < 12 * 1001 && i <= k; ++i) {
                      best_coin = max(best_coin, dp[i]);
              }
      

      Starting from i=1, instead of i=0, breaks for the case

      2 0
      2 1
      4 14
      

      because the optimal solution (take the second coin using zero operations) has zero cost.

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

My opinion about problem E.

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

For E, is this lemma correct?

  1. There can be atmost 2*n distinct MSTs.
  2. These 2*n MSTs will occur in 2*n non-overlapping ranges from [1, 10^8]
  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    O(m^2) distinct MSTs.

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

      Care to try hacking my code? It should run in $$$O(m ^ 3 \log ^ 2(m) + k (n + \log(m)))$$$ if that is the case which should be too slow to pass, even in 4 seconds.

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

        Any hints for E?

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

        Lol!!! Have you hacked into the system ? I did the same complexity but still get TLE on Test 8, while your code ran in ~ 100ms. I even removed one log(m) factor by not sorting every time in binary search but just merged the negative weights and positive weights by their abs value. Still I am getting TLE. submission

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

          I think I calculate optimal MSTs in a different manner from you I think. There is no case in any of the tests (including hacks) that has number of MSTs $$$> m$$$. So my solution actually runs in $$$O(m ^ 2 \log^2(m) + k(n + \log(m))$$$.

          For example, on test 8, my code finds 252 ranges, your code finds 32000.

          aryanc403, any ideas on how to generate a case with number of MSTs $$$> m$$$? I can't seem to either prove this idea or generate such a case.

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

            Oh! Cool... Then it seems that about (m^2 — m) swappings of edges are unnecessary. i.e. They dont change anything in the spanning tree. I get that it should be definitely less than m^2 but only m msts are there. Interesting. Anyways thanks for the interesting result. It would be nice to see atleast some intutive proof from aryanc403 or someone.

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

              Me neither. I tried hacking his soln but couldn't create a test case with more than O(m) MSTs for his soln.

              Rn, I don't have any proof for O(m) upper_bound on MSTs.

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

Hint for problem D

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

    NHK bro?

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

    k doesn't need to be 1e6

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

      Can you tell me how did you derive that during contest?

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

        if you try to calculate how many steps are needed to reach numbers 1 to 1000 (using simple dp) you will notice that there is an upper bound over these numbers (which is 12). So the maximum usable value of k would be 12*1000 and the rest is standard knapsack problem

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

For problem E which group of x should suffice to check? I tried all edges values and every (edge[i]+edje[j])/2 values but got WA

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

In problem D, Ceil(log2(bi)) is star I think because this many steps is required to change 1 to the particular number.It's just a theory based on 1 + (1/1) => 2 + (2/2) or 2 + (2/1) etc.. for each number.

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

Video Solutions for A-D for anyone looking

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

D was a nice question. 0-1 Knapsack DP hidden behind a good observation — max operations on any index i can be atmax 12. So if k>=12*n, ans would be sum of array c otherwise apply standard DP for 0-1 knapsack.

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

problem d approach is as knapsack dp problem ?

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

Problem F is nice .

But I wrote the dfs order as index ,and debug for about 40 minute (how can this pass the first 12 tests ???).

And I found this silly mistake in the last 30 seconds ..

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

    Share my solution here :

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

Problem A is exact copy of this TOPCODER ROUND. Even the number 7 is same.

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

Solution for C ?

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

    Notice that the sum of k<2*10^5.

    That means the solution should be O(n).

    To Check who wins- find number steps needed by both to win (that means if the character kept attacking how many rounds are needed to defeat the monster and vise-versa)

    character_steps = ceil(monster_health/character_damage)

    monster_steps = ceil(character_health/monster_damage)

    if character_steps<=monster_steps then character wins (First chance is of character so <=) Checking who wins is o(1)

    To find all possible combinations in the way we can use the coins- we can go from 1 to coins (i) and use i as the coins used for damage boost and use coins-i as the coins for health boost and add the boost to the damage and armor. We can do this in O(n)

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

It seems that D can be passed in $$$\mathcal{O}(nk)$$$ time

Maybe it will be better if the time limit is changed to 1s ...

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

    It's not actually $$$O(n\cdot k)$$$ where $$$k\approx 10^6$$$.

    Since the number of operations needed for any $$$b_i$$$ to get constructed is at max $$$12$$$, if $$$k\ge 12\cdot n$$$, you can simply print $$$\sum_{i=1}^n c_i$$$. Otherwise you can use a knapsack dp solution so solve the problem in $$$O(n\cdot k)$$$ time where $$$k\lt 12\cdot n$$$.

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

      why?, if k >= 12*n then we can take all coins?

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

        If $$$k\ge 12\cdot n$$$, it is possible to make all $$$a_i$$$ equal to $$$b_i$$$. Hence we can collect the value $$$c_i$$$ for all $$$i$$$'s.

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

      But in fact,some guys solved this problem in $$$O(n\times k)$$$ and I cannot hack them. Are there any stronger cases than this? QaQ

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

        I can't open the link you gave, it says "access denied".

        Can you provide me with such a solution?

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

      Yes I understand that, but what I want to express is you can pass this problem even if you use the 01-pack dp for every $$$k$$$ but not just when $$$k\le 12 * n$$$

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

How to solve E?

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

What is the hacking phase??

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

    There might be some solutions which either shouldn't pass according to the given constraint or are actually wrong but the systems tests don't cover the cases where they fail.

    Codeforces gives the users, an opportunity to identify such solutions and hack them (submit a valid test where they fail). Obviously it does not guarantee $$$100\%$$$ strength to the new test set formed after hacking.

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

Really nice contest.

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

Today is the day I will learn Knapsack, Thanks for the round

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

In problem D how do I find the number of operations for each number I tried to do it but got WA here is my code: https://ideone.com/Fm0aPE

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

    I precompute them using BFS. Find the shortest path from 1 to all nodes

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

    You can write a brute force dp for this. Just make sure you have an idea about dp solutions.
    Consider $$$dp_i$$$ stands for the minimum number of operations required for making the number $$$i$$$ starting from $$$1$$$.

    Then, it can be seen that before forming the number $$$i$$$, we might have had a number $$$j$$$ such that the value of $$$\lfloor \frac{j}{x} \rfloor$$$ was equal to $$$i-j$$$ for some $$$x$$$ (because that's the only way $$$j+\lfloor \frac{j}{x} \rfloor$$$ will become equal to $$$i$$$). Let's iterate on $$$j$$$ too. We will then need to find the value of $$$x$$$ (if it actually exists).

    Finding the value of x
»
2 года назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

In problem D , I assumed x should be a divisor of a[i] out of nowhere, and now I won't reach expert because of this.

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

Help needed in Problem D. This is my solution What I did was calculate operations for every b[i] and then select those with best (c[i]/operations) in decreasing order. But this gives WA. Any ideas why?

EDIT: The way I calculate minimum operations is probably wrong. I'll just wait for the editorial.

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

    I think you answered your own question. You can't solve 0-1 knapsack with greedy.

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

      I am actually taking the entire points and not just a fraction of it. I wrote greedy because I sorted the numbers in decreasing order based on their worth (points divided by operations) and selected them greedily. Maybe I should remove greedy knapsack from the comment if it is confusing.

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

        What I am understanding from your comment and code is that you are trying to solve this knapsack which is impossible with greedy.

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

    Never be greedy :p

    c — 10, 4 operations — 2, 1 k = 1

    according to you 10/2 is better than 4/1 but we cannot take 10/2 as limit is k=1.

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

      I am checking for that as well, if operations are greater than what is allowed I skip it.

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

        No the point is that you cannot solve the knapsack problem with a greedy approach. Take for example values — 3, 2, 2, 0 and cost — 2, 2, 2, 1 and capacity=4. If we take elements greedily, we will take the first element because 3/2 is more than 2/2. However, the optimal solution is to take the second and third element,so this approach fails.

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

I've wasted too much time and energy on D thinking b_i<=1e6. Sad

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

I like the idea of E but its implementation is way out of my skillset :(

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

I have a question, does an unsuccessful hacking attempt on Hacking phase gives us any penalty in some ways?

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

In Problem D, number of operations to convert 1 to x is (index of MSB in x) + (number of set bits in x) - 1

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

    No need of fancy math. run n*n bfs as {1,1}

    {i, steps} -> {i + (i/j), steps + 1} for all 1<=j<=i

    states = 10^3, TC: 10^6 bfs

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

      No need for fancy BFS. Just run 2 for loops =)

      int w[1001];
      for (int i = 1; i < 1000; i++)
          for (int j = 1; j <= i; j++) {
              const int t = i + i / j;
              if (t <= 1000)
                  w[t] = min(w[t], w[i] + 1);
          }
      
  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    How do you know this regularity?

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

    Have u tried? I did the exact same thing first but got 2 WA. Then I switched to BFS.

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

    I did this in contest and got wrong answer, brute force implementation after contest gave AC, are you sure this is correct? (maybe I implemented it wrong)

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

    This isn't correct:

    Try for 19: 10011
    Index of msb: 4
    setBits: 3
    Your ans: 4+3-1=6
    Actual answer: 5
    How to reach: 1->2->4->8->16->19 [19 = 16 + 16/5] in total 5 steps

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

    I did this mistake too.

    15 = 1111 Here ans ≠ (3) + 4 — 1 = 6

    But optimal soln is 5 (1->2->4->8->12->15)

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

Happy Chinese New Year for every Chinese!Hope all of you will get good grades in xcpc(icpc&ccpc) in this year!

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

What happened to rainboy??

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

Is standing broken?

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

Any hint for problem E?

I got WA on test 7, I mapped all queries, if a query occurs an odd number of times I sort all edges by abs(x — wi) and find MST with Kruskal's algorithm.

My code: https://codeforces.com/contest/1633/submission/144721913

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

E was too hard to code

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

When you get traumatized by interactive binary search problems xd

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

E was too hard to code

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

In problem D, Why I am getting tle on testcase 12 https://codeforces.com/contest/1633/submission/144763541

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

    $$$k = min(k, 12n)$$$

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

      after considering this condition, still got TLE under python3 .... here is my code

      BTW, I found another code, which was accepted during contest, but also TLE now...

      really weird ....

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

      Actually you could solve it even without that optimization =)

      I use the following justification:
      1. Knapsack performs $$$k * n = 10^6 * 10^3 = 10^9$$$ operations.
      2. CPU speed is 2.4Ghz or $$$2.4 * 10^9$$$ operations per second.
      3. If we access the data properly, CPU will utilize it's fast cache and registers instead of waiting for data from RAM (RAM is 10 times slower than CPU cache).
      4. We have 2 seconds limit on the problem, so we have some room for overhead computation and round trips to RAM.

      144830143


      By the way, I like the code that I got after incorporating the idea of short circuiting.
      That is, we don't do $$$dp$$$ if $$$k$$$ is large enough.
      This short circuiting allows us to reuse unoptimized code from above without using magic constants k = min(k, 12 * k). Everything works out by itself and the code would work even if we have a different problem with larger constraints, so we don't need to recalculate new constant for 12 * k.

      Short circuiting

      144830112

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

Can someone clarify this? In E when I used edges as vector of vectors , it gave TLE. In some AC submission I saw they have used structure for edges. When I used structure instead of vector, it passed. Why this behaviour?

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

I didn't know there is a space optimized version of solving KnapSack

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

Is O(NK + KlogK) the intended solution for E or is there something better? I am processing the queries in a sorted order and just updating the edges in the MST only when the sorted order of the edges changes in the next query. It is easy to see that the sorted order of the edges won't change more than M * M times.

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

for problem D, anyone succeed to get accepted by python3? why I always got TLE? here is my code

BTW, I found another code, which was accepted during contest, but also TLE now... weird ....

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

In Problem D test case

4 4
1 7 5 2
2 6 5 2

cant we make [1 1 1 1] -> [7 1 1 1] in 4 steps, as conversion from 1 to 7 takes 4 operation and then answers should be 6+2+2+2 = 12. Whats wrong here

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

Problem E. There can be at max e*e event points where we need to re-calculate MST. giving e*e*e*log(n) as preprocessing time.

for given x we need to find y<=x in above event point list and do some calculations.

I did it with y = map.lowerbound(x) -> Gave TLE complexity O(k * log(e * e))

People did it with presorting x and using two pointer to get y for given x- TC: O(k * logk)

SInce log factor of sorting is better than log factor of map, hence i got tle.

I think problem shouldn't have such tight constraint that sorting pass but map.lower_bound() fails. What do you guys say?

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

    You could presort y and lower_bound for every x query (without using two pointers and presorting x), map just has terrible constant factor.

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

Can someone tell why this method of finding the minimum number of operations to convert 1 to b[i] is wrong :-

This is what i've done — Im finding the nearest power of two (call this num) for b[i] and then convert num nearest power to b[i]. To do that first i find the difference between b[i] and num and update num greedily such that num + [num/x] <= b[i] till i get num == b[i].

This is the piece of code for finding this minimum number of operations.

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

    Greedy doesn't work because you cannot make sure that by incrementing with the largest possible move will lead into minimum possible weight.

    Example

    So apply dp here too (similar to coin change).

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

I usually don't write such stuff, but I must say I'm really disappointed with the pretests for problem C. For such a short mathy problem, You'd expect to give constraints in a way that don't give an overflow with a pretty standard solution. And if there is a standard solution that gets an overflow, it's only right to give a not-so-difficult-to-construct pretest that prevents it.

For educational rounds it's even more important to have strong pretests on the easier problems, due to the fact each problem weighs the same.

Thanks, a CM that instead of getting to master for the first time, gets a -95 :(

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

    Yeah already got a contender for the worst problem of 2022.

    Hey but let's rejoice we can just move ahead with int128 from here onwards and forget about these silly problems the setters come up with.

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

    Tbh, most of the times there is at least one problem with ridiculously high constraints in Edu rounds.Moreover, almost always the pretests are weak to encourage hacking. Maybe you have been just lucky to not get FSTed before.

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

      I haven't seen that many problems with ridiculously high constraints (that can't be handled by long long) in Edu rounds. Can you give examples? Moreover, it sounds extremely weird to me that the pretests are weak to encourage hacking. After all, the purpose of the pretests is to validate solutions... But I agree that I might have been somewhat lucky to not get FSTed until now.

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

    Yoav What do you mean by "You'd expect to give constraints in a way that don't give an overflow with a pretty standard solution"? Pretty standard solution here is to use long long and it got AC here

    https://codeforces.com/contest/1633/submission/144683828

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

      Look at my hacked solution. In my opinion my approach is quite standard, and is correct but gets an overflow. After checking again the constraints it is easy to see there can be an overflow. So if the constraints are made in a way that there could be such overflow, there should be pretests that cover it.

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

Good contest and interesting tasks !

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

Are editorials released?

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

Can someone please help me figure out why my solution for D isn't working? 144791596

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

In my opinion, 2 seconds TL on problem D was too much. It let some unoptimal solutions pass.

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

Hey There!

Can someone please tell me what stress testing is and how to use it during the contests?

I received this suggestion from some revered person :"You can try stress-testing to find the test cases you're wrong at" I often apply the right logic in contests but end up with failing a few test cases.

Best, Wandering Brain

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

    You can write naive solution (even exponential one), generate some small test cases and compare your solution against naive on those small cases. To make it efficient you should automate the process of generating random test cases and comparing your solutions.

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

I should have done problem C in python :( (Wrong Answer on testcase 13 due to Overflow)

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

Hello guys. I'm new in codeforces and this was my first contest. I solved one problem. Will my rating increase?

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

FSTforces :(

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

    +100 delta to negative delta

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

      Got FST on both C and D today.
      If this had happened on Topcoder, it would not be unusual because TopCoder emphasizes on proving your solutions with your own edge cases as their questions are usually more about implementation (imho).
      But this is certainly not what I used to expect from Codeforces rounds as the questions are usually more about coming up with the idea and being guided about whether that works or not with pretests.

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

    what is FST?

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

fstqwq

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

I figured out that in D, knapsack was the way to go, since we can interpret that weights are no. of operations to reach each element. I found the required way to reach all elements in nlogn, and since N was <=10^3, thought knapsack would work, but k was <=10^6. I do not know how to lower this. any hint would be appreciated

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

    Using DP on the number transitions, you could pre-compute the number of steps required for each of the numbers (1->1000), and because this was kind of logarithmic (max. 12 steps), you could effectively reduce 1e+6 to around 12000, which is manageable.
    My Submission (has FSTed)

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

      thank you, I'll try again. Why wasn't this came in my head earlier

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

    The maximum operations required to obtain any b will be logarithm in nature so the actual max value of $$$k$$$ will be $$$nlogn $$$. Hence, the problem becomes knapsack DP with complexity of $$$n*n*logn$$$. Check out my solution, it did not FST

    144759233

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

Weak pretest for problem C :(

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

I suddenly realize that in Educational Rounds solving ABD with more penalty time will be ranked lower than solving ABC with less penalty time. So, in such rounds instead of solving harder problems it's important to guarantee the solved easier problems are correct.

I initially "solved" ABCD but just got FST on C which makes me feel sad. (C makes me realize "long long overflow in C++". Perhaps I should use Python 3 for all such large integer problems.)

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

IMO, This is one of the worst contests ever. Felt like the tasks as well as the test was created just as a formality. Please don't create this type of contest.

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

    Can't disagree with you, I always highly rate the educational round but this one was far below standard.

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

I'm down-voting this contest and this post , because of weak testcases for problem C and problem D , that causes me negative delta! From ~2800 to ~8000 ! This content damaged my rating a lot. But actually the problems were interesting.Thanks.

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

    Couldn't agree more! Weakforces

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

    I dunno know why you were downvoted. If the pretests are gonna be this weak they might as well not include them at all and leave participants to make submissions on a gamble.

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

Weak test cases for D!!Even an O(nk) solution passed.

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

144799151 Problem C, my solution is failing on TC 13. Can anyone please point out what's wrong?

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

144799151 Problem C, my submission is failing on TC 13. Can anyone please point out what's wrong?

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

    Its overflowing when you do the operation $$$(attacks - 1)*dm$$$ . Very weak testcases this time

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

Pretests for Problem C were very weak, I had an overflow in my code and it passed, if pretests were strong then I would've gotten a WA but usually codeforces tells us if we have an overflow and I'd have been able to AC.

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

Two Contests back : I might become CM Now : Specialist , I am coming

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

Can someone please explain why this submission for D is failing test case 21?
The Submission
Thanks.

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

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

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

The test data in question C makes the variable overflow of "long long" in some incorrect writing, which is nicely designed

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

Can anyone explain why the remaining queries in problem E are defined by the modular arithmetic formula instead of straightaway giving them? Edit : Seems like it was because the number of queries is very large my bad

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

I got accepted in A, B and E. But I FSTed in C, D.

New year, New FST, New -189, New Candidate Master -> Expert.

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

From now, I will check overflows even after using long long. :(

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

In D, I got a TLE just because I created a new function to calculate my ans. Can anyone explain how does that work?

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

    For your D just apply a check that if k >= 12 * n print the sum of all c[i]. Because at max it would take 12 operations to convert 1 to b[i].

    You don't need to go for k = 1e6. Your AC code for D runs in 1996ms, after applying the check it runs in 15ms.

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

gone from positive delta of 160 to negative delta of 20....XD. D got hacked and C failed in system tests due to overflow. I hope to improve in next round

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

    my 3rd contest ever C failed in test 10 after showing accepted whole night . could have reached 1k rating now stuck at 898 only.\

    python solution with same logic now shows accepted.

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

This was my first round in Codeforces, and I am going to share my ideas while solving the problem A and B.

1a. Problem A — O(1) idea

during the contest phase, I did not come up with the idea to change the last digit only (which was, I think, the expected solution). Instead I focused on the fact that the input is 3 digits maximum, and the divisor is 7. 1 (mod 7) = 1, 10 (mod 7) = 3, 100 (mod 7) = 2. Therefore I thought it would be possible to make up every difference in 0~6 with these 3 digits. However I decided that this is not the correct solution as it would be impossible to find all the cases in 2 hours for me.

1b. Problem A — BFS idea ( O(27^steps)? ) (My final solution)

This time I found that the input is only of the two cases, TWO DIGITS or THREE DIGITS. I thought BFS would finish relatively early. (This speculation turned out to be correct, and it all ended in one step.) So I did a BFS on changing each digit to 0~9 (non-leading digits) or 1~9 (leading digit), and the runtime was only 15ms. Sounds good enough to me.

2a. Problem B — O(n^3) idea

I only had this idea for a very brief amount of time, and I knew this idea would always TLE out on even the weakest cases. and you probably guessed what it is. Yes, the good old "counting every substring we could find". Good thing I didn't have to try this.

2b. Problem B — O(n) idea

I really hesitated on this idea, and I could not easily prove that this would always work. I did focus on the fact that we have to maximize the amount, and later on it turned out to be the correct approach but I had the suspicion of DOES THIS REALLY WORK for probably 20 minutes or so. It's the classic answer of (cnt0==cnt1)?cnt0-1:min(cnt0,cnt1) where cnt0 and cnt1 is the amount of 0's and 1's after counting the whole string. I submitted the answer as a gamble to myself, and I am still amused that this turned out to be the correct answer.

So yes, this is a list of my ideas in my first Codeforces round. I really hope I have a better performance next round or so, but I would really appreciate learning new ideas from Educational Rounds and Div.3/Div.4 Rounds.

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

In educational codeforces rounds, I personally think that each problem should be given points as given in other Div2 and Div1 contests. Because if some person was not able to solve C due to some small error but was able to solve E. Still, he/she will be having less rating than others because time taken to solve E was more than C.

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

Happy new Chinese year!

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

Happy new Chinese year!

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

Problem D was so simple yet so tricky at the same time :) Great Problem

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

When will the official editorial be released ?

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

for Problem B Minority, if input is 1100 then the output according to answer is 1, but since both number of 0's and 1's are same, so the output should be 0. If it is 1, can someone please explain how?

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

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

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

Can anyone help me, why I am getting run time error in Problem E 144915859

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

Finally solved 3 problems!