Автор awoo, история, 6 месяцев назад, По-русски

Привет, Codeforces!

В Nov/24/2023 17:35 (Moscow time) состоится Educational Codeforces Round 158 (Rated for Div. 2).

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

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

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

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

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

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

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

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

Such a short and clear announcement I hope problems statements be like this too!

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

Excited for this round! Initially I didn't like edu rounds, but I've started liking them more nowadays.

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

I'm excited to this round, I hope that I'll enter pupil after it :), Good luck to everyone ^_^

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

Wow,So exciting to see this round.I hope, inshallah! I will learn something new from this contest.

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

Happy Fibonacci Day ;)

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

I will give my best performance in this game!

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

Good Luck!

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

CR7 > Messi

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

let us Do our Best =D

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

Wish Rating ++

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

Pupil, I'm comming for you.

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

Education

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

C > B > D

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

speedforce

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

SpeedForces

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

why in D, test case 1 the output 7 is incorrect?

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

    There are 2 equivalent worst-case lightning strikes.

    Here is the test case: 2 1 5 6 4 3

    First example:

    • 8 damage onto 6
    • 7 damage onto 5
    • 6 damage onto 1
    • 5 damage onto 2
    • 4 damage onto 4
    • 3 damage onto 3

    Notice the damage toward the end is exact so you can't do better than 8. The other worst case is:

    • 8 damage onto 6
    • 7 damage onto 4
    • 6 damage onto 3
    • 5 damage onto 5
    • 4 damage onto 1
    • 3 damage onto 2

    Again, we have exact damage at one point, so we can't do better.

    EDIT: Fixed bad formatting.

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

      what? means do cf is asking us to check only 2 ways and get the ans for Div2D?

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

        No I was just giving examples why it can't be 7. We have to account for our worst case possibilities; it isn't how can we play optimally, since the lightning strikes are random.

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

      But what happen if 8 damage onto 2? Or it doesn't the worst case what's the worst case mean? Thankyou

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

        "Firstly, Vasya chooses an index i of some monster (1≤i≤n) and the initial power of the spell x"

        the first monster can be chosen. If you choose the 6-hp monster, you will certainly kill all with 8 spell power.

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

          oh i get it now! thanks you. so hard to understand it for me

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

    yeah I was also getting 7 as the output. as we can move from 6->5->4->3->1->2. Here 7 looks like optimal ans

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

      It doesn't matter if we "can move" there. We always have to take the WORST case.

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

    Suppose you start by hitting the 6 HP monster, and the following happens:

    • hit 6 HP monster with 7 dmg

    • hit 5 HP monster with 6 dmg

    • hit 1 HP monster with 5 dmg

    • hit 2 HP monster with 4 dmg

    • hit 4 HP monster with 3 dmg

    • hit 3 HP monster with 2 dmg

    The last monster lives.

    If you pick any monster further left as the starting point, the 3 HP monster lives in some scenario. If you pick any monster further right as the starting point, the 2 HP lives in some scenario.

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

    Because...a power of $$$7$$$ isn't enough to kill all monsters? Why do you think it is enough? Remember that you can only choose the starting monster, you can't affect the order they're killed in after that.

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

Bruh I was convinced D was supposed to be solved with monotonic stack, turns out it was much easier than that.

Also had to completely guess C, not a good time.

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

Where's Tutorial?

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

Why is my solution for B not working? subtract the minimum ovral from all elements subtract 1 from it add it to the answer, then for each island between 0s add the maximum to the answer . why is this wrong?

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

    Islands can be created while running. For example

    2 4 4 3 5

    Let's say you start by removing 1 from all :

    1 3 3 2 4

    remove min from all and add to answer

    0 2 2 1 3

    ans = 1

    Your answer would then be to add 3 to this (return ans = 4) But if you run the algorithm, after a pass you're going to end up with :

    0 1 1 0 2

    ans = 2

    Problem here is you created a new island that you didn't account for, so the answer would be 5, not 4 !

    You had to take care of the case when you start descending (4 -> 3 in original array) and then you start ascending (3 -> 5 in original array)

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

I thought C was harder than D lol

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

Where's Tutorial?

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

Thanks for the great round! Could someone please share solution to D?

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

    Fix some position of $$$k$$$, then find the lowest possible damage a monster at each position could receive.

    For $$$k=1$$$, the first monster receives at least $$$x$$$ damage, the second at least $$$x-1$$$, the third at least $$$x-2$$$, and so on.

    For $$$k=2$$$, the first monster receives at least $$$x-n+1$$$ damage (when only the last lightning strike hits it), the second receives at least $$$x$$$ damage, the third receives at least $$$x-2$$$ (in the worst case, the second lightning strike hits the first monster, and the third strike hits the third monster), and so on.

    Now you'll find a pattern:

    • For $$$i<k$$$, the minimum damage dealt is $$$x - n + i$$$ (zero indexed)

    • For $$$i=k$$$, $$$x$$$ damage is dealt

    • For $$$i>k$$$, the minimum damage dealt is $$$x+1-i$$$

    So for any $$$k$$$, the minimum $$$x$$$ required is $$$\max(\max_{i<k}(a_i+n-i), a_k, \max_{i>k}(a_i - 1 + i))$$$. You can use prefix and suffix maximums to compute this for all values of $$$k$$$ and return the minimum answer.

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

Can someone explain me what is incident edge?

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

    An edge is incident to a node if that node is one of the edge's endpoints.

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

    These terms should be defined in the statement imo. Also, authors can use more familiar terms, like "degree", which should also be defined

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

      It's not easy to know which terms are "well-known" and which are not, especially if you aren't a native english speaker. There will always who doesn't know some term. That's why the clarificiations -system and google exist.

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

        I often see very common terms like tree, permutation, subarray, subsequence etc. defined. Gave me the notion that defining these terms was the standard.

        Although I don't need it, I like it better than without.

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

E>>>D, D and C are relatively easy compared to other edu rounds.

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

    D maybe, but not C

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

      C is too difficult to guess

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

        Yeah, kind of

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

        messed it up, but i dont think its too bad :)

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

        C is far easier than B imho but I guess people are good at different styles of problems.

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

        What I think is that people below 1500 rating think too greedy that today's C will be easier for them but the people above 1600 try to think in a more generic way that's why they were not able to come up with the logic that answer will only depend on the highest and lowest element.

        We should try to balance both things I guess to perform the best.

        I also was not able to solve C but solved D in just 15 mins, sadly :(

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

how to solve B? how to solve C?

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

    B:

    When a teleportation happens, there is a source and destination. My approach was to count how many source teleportations are required and how many destination teleportations are required.

    For each $$$i$$$ in which $$$c_i > c_{i - 1}$$$, there must have been $$$(c_i - c_{i - 1})$$$ teleportations with destination $$$c_i$$$. Add that to the destination count.

    For each $$$i$$$ in which $$$c_i < c_{i - 1}$$$, there must have been $$$(c_{i - 1} - c_i)$$$ teleportations with source $$$c_{i - 1}$$$. Add that to the source count.

    Furthermore, add $$$c_1 - 1$$$ to the destination count, and also add $$$c_n - 1$$$ to the source count. Return the maximum between source and destination counts.

    C:

    Consider when there are two distinct values $$$a$$$ and $$$b$$$. No matter which value of $$$x$$$ you pick, the difference between $$$a$$$ and $$$b$$$ reduces to either $$$\left\lfloor\frac{b - a}{2}\right\rfloor$$$ or $$$\left\lfloor\frac{b - a}{2}\right\rfloor + 1$$$. The former is optimal and can be achieved by simply choosing either $$$a$$$ or $$$b$$$ as your $$$x$$$.

    If you have more than two distinct elements, all you need to do is ensure that the smallest and biggest values coincide, and this guarantees that all other values will coincide too. Simply find the difference between the largest and smallest elements, and then return the number of bits in the binary representation for this difference.

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

      For B: you don't need to consider source counts at all. It suffices to count how many times the token must be teleported to each square, which is $$$max(c_i - c_{i - 1}, 0)$$$ for the $$$i$$$-th square ($$$i > 1$$$) and $$$max(c_i - 1, 0)$$$ for $$$i = 1$$$ (since the token starts at square 1 for free).

      So the solution is basically $$$\sum_{i=1}^n \max(c_i - c_{i-1}, 0)$$$ if you define $$$c_0 = 1$$$.

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

        I just realized that source count must always be equal to the destination count, due to the way they are calculated, so yeah, you can count either one and it should be the answer.

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

      why does coincidence of the smallest and the largest number ensure that all the numbers in between coincide too?

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

        Think about the problem in binary. You are performing $$$m$$$ operations, where at each operation, you add a value $$$x_k$$$ ($$$0 ≤ k < m$$$) to all $$$a_i$$$ and then shift right, discarding the least-significant bit for each number.

        Here is one useful insight: if you have a solution of the form: add $$$x_0$$$, shift, add $$$x_1$$$, shift, ..., add $$$x_{m-1}$$$, shift; then there is an equivalent solution of the form: add $$$s$$$, shift, add $$$0$$$, shift, add $$$0$$$, shift, ...; where $$$s = x_0 + 2x_1 + 4x_2 + \dots + 2^{m-1}x_{m-1}$$$; i.e., the number of shift operations stays the same, but you add everything in the first operation.

        So a different way to formulate the problem is: pick integers $$$s$$$ and $$$n$$$ so that $$$shift(a_i + s, n) = shift(a_j + s, n)$$$ for all pairs $$$i, j$$$, and $$$n$$$ is minimal.

        Now if you have $$$a_i ≤ a_j ≤ a_k$$$, then $$$shift(a_i + s, n) = shift(a_j + s, n) = shift(a_k + s, n)$$$ iff. $$$shift(a_i + s, n) = shift(a_k + s, n)$$$, so you only need to consider the minimum and maximum values of $$$a$$$.

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

      For C: it's useful to realize that to minimize the difference after division you only need to consider adding either $$$0$$$ or $$$1$$$.

      Specifically, if $$$a < b$$$, then:

      • If $$$a$$$ is odd, and $$$b$$$ is even, you must add $$$1$$$.
      • If $$$a$$$ is even, and $$$b$$$ is odd, you must add $$$0$$$.
      • If $$$a$$$ and $$$b$$$ have the same parity you can add either $$$0$$$ or $$$1$$$.
    • »
      »
      »
      6 месяцев назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      Thanks LightBrand99 for the explanation. For problem B could you please guide through your thought process (ie, how you came up with the above solution)?

      my thought process - couldn't solve with this
      • »
        »
        »
        »
        6 месяцев назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        The task B is:

        you have an array $$$a_1,a_2,\ldots,a_n$$$. One operation use choose $$$[l,r]$$$ and decrease all $$$a_i$$$ by $$$1$$$ ($$$l \le i \le r)$$$.

        This is basic problem. Answer is $$$\sum\limits_{i=1}^{n+1} \frac{|a_i - a_{i-1}|}{2}$$$, where $$$a_0 = a_{n+1} = 0$$$.

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

        To solve this on contest you just need to notice that in this problem your operation is choosing subarray and decreasing all values in it by $$$1$$$.

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

what is the solution for C? I chose x equal to 0 until the last one decided to be 0 or 1. can you give me some idea. Thankyou

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

    my solution was if the max element in the array is even and the min element in the array is odd we choose 1

    else we choose 0

    we keep doing this until the array become equal

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

    If the parity of the max element and the min element is same it doesn't matter what you choose, the difference will be halved anyways, as the difference would be even too.

    Otherwise, the difference is odd and so it is better to choose 1 if min element is odd and choose 0 if its even. You can infer the same wrt max element in this case.

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

    Just always choose min value.

»
6 месяцев назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится
  • In problem C :
  • Why is this solution rejected?
  • in test case ( 2 )
  • 2
  • 5 4
  • »
    »
    6 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

    Assuming that you're talking about this submission: 234119469

    Notice how you printed an extra $$$5$$$ for the first test case even though the number of operations was $$$0$$$. The contest system thought that this $$$5$$$ was your number of operations for the second case (it was the next token in the output file) and $$$5 > 2$$$ so the verdict is WA.

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

nearest integer to 1.5 is 1 or 2 ?

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

A. The answer is max(a[1], a[i+1]-a[i], 2*(x-a[n])), where 2*(x-a[n]) means you need to go from n-th gas station to point x and go back.

B. The operations means you need to choose some segments to add 1 to these segments, and find the minimal amount of segments. Assume a[0]=0 we have ans=sum(max(a[i]-a[i-1],0))-1 where -1 means we don't need to teleport for the first segment.

C. If you choose x[1], x[2], ..., x[k] for operations, the final value of a[i] will be floor((a[i]+x[1]+2*x[2]+4*x[3]+...+2^(k-1)*x[k])/2^k), so in order to make a[i] become equal, we need that max(a[i])-min(a[i])<2^k because x[1] can be chosen arbitrarily.

D. We use binary search for answer, and we need to check if x is a valid answer. Assume we use the spell on the i-th monster, and for j<i, the minimum possible damage it will take is x-(n-i)-(i-j)=x-n+j, which means we must have x-n+j>=a[j] <--> a[j]-j<=x-n. For j>i, the minimum possible damage is x-(i-1)-(j-i)=x-j+1, which means x-j+1>=a[j] <--> a[j]+j<=x+1. And we must have a[i]<=x. Therefore, if we pre-calculate prefix maximum of a[j]-j and suffix maximum of a[j]+j, we can check all i for 1<=i<=n if i-th monster is a valid initial target in O(n).

E. The problem means we need to build a subtree from the initial tree, and take the sum of a[u] for all deg[u]!=2. So we can let dp[k][u]=the answer if the highest node in the tree we build is u, and deg[u]=k. Note that we don't need to distinguish cases where k>=3.

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

I think D is easier than C. It took me 1h to solve C, but D only took 15min.If I slove D first may I can have rk1000- :(

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

closest integer to 1.5 is 1 or 2 ? and why

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

    Are you talking about problem C? If yes, you probably missed the part where it said rounding $$$y$$$ down to the nearest integer. We're rounding down and the nearest integer below $$$1.5$$$ is $$$1$$$, not $$$2$$$.

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

      crying inside wasted all my time in problem c....... crying outside ...... i will become candidate master by june 2024

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

My solution for problem C (234118115) is to choose x = min and keep making max = (max + min) / 2 until max == min, not pretty sure about this but got AC.

I hit the tab SUBMIT CODE when there was 10 seconds left but it kept loading the page until the message Contest is over displayed.

Thank you guys for the contest!

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

    Did this, but was getting some TLE so added some ugly heuristics to try and make it work. I'm really bad at C++ apparently ahhhhh. Welp thanks for confirming at least that my idea was sound !

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

    What is the logic behind choosing x = min? I always chose x = 0 or x = 1.

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

      If x = min or x = max, the difference between max and min decrease by the floor of half. This is easy to observe mathematically. For other choices, it is possible for the difference to decrease by either the floor or the ceiling of half, depending on the parity of the original min, original max, and your chosen x. This requires a little more case work for a mathematical proof, but one can intuitively deduce that the difference can't possibly be reduced further than the floor of half, so it is optimal to stick with that.

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

    I just tested with some cases by choosing min and it seems to be correct, plus there was just about only less than a minute left (and I couldn't make it in time as in my comment).

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

As a not tester, i don't know problems.

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

I think D is easier than C. It took me 1h to solve C, but D only took 15min.If I slove D first may I can have rk1000- :(

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

With just 3 seconds left, I got the adrenaline rush.

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

Huge gap between ABCD and EF, not to mention that ABCD are probably under 1500-ish.

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

 With just 3 seconds left, I got the adrenaline rush. A SuperOverKill BFS 234117586

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

    Wow, good job

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

    WOW but it seems your code is semi-complicated while the solution is each time x = max_number + 1

    because, (x+x+1)/2 = x while (x+x+2)/2 = x+1 so what ever happened all numbers will not exceed max_number and make the min_number be equal to max_number you can check my submission 234086134

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

    Wow, good job;

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

C > D > B > A

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

    For me, it was D > B > C > A. C came intuitively to me and I found D much harder.

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

Problem sets seemed really interesting to me...Hope to see more contests like this!

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

Solved C but couldn't solve B because I forgot to use long long instead of int and somehow missed that as I was staring at my screen for an hour. It hurts so much... :(

Oh well... We live and we learn! I'm new at this so there's so much for me to learn, including the absolute basics lol.

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

    That's why I use

    #define int long long
    

    I know it's bad practice but I've made that mistake way too many times.

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

    can you explain your answer?

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

      B: I noticed a pattern from the provided input->output examples that the result is just the sum of the difference between each element and the element before it but only if the element before it has a higher value, plus the final element — 1.

      C: Just always pick the minimum element in the array as x. Always. The number of times it takes for all elements in the array to equal each other is equal to the number of times it takes for the maximum element to get to the minimum element with the given equation.

      So, I did just that. Stored the minimum element and the maximum element, and then made a while loop that does the operation with a counter.

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

Very interesting contest but I had a connection problem so I delayed for 20 minuets and solved " D " after the contest end :(

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

Really interesting tasks and one of the most balanced round for last months. I will be glad to see next rounds from the authors!

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

Since there is no yet editorial: how to solve F?

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

Thank you for problem F! It was really satisfying to solve.

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

Problem C:

234129053

can someone please explain why I am getting memory limit exceeded for this code ?

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

In problem D, can anyone explain why I'm getting WA on test 6:

submission

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

    for test n = 7 a = {5, 5, 5, 4, 4, 4, 4} your solution return 11 but right answer is 10

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

could smbd prove greedy solution for B, pls?

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

    For first move, you will need a[1]-1 moves always

    you can always move to A[i] from A[i-1] if A[i]<=A[i-1] without Teleporting

    But if A[i]>A[i-1] you need to Teleport A[i]-A[i-1] times

    Ans can be

    $$$ A[1]-1+\sum_{i=2}^{n} max(A[i]-A[i-1],0)$$$
  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    That greedy solution you are talking about? Probem B is: we have array $$$a_1,a_2,\ldots,a_n$$$. Find minimum number of following operations we have to do to make array all zeroes. Operation is take a subsegment $$$[l,r]$$$ and decrease all values by $$$1$$$.

    It's easy to proof that if we use our operation on segment $$$[l,r]$$$ and can use it on segment $$$[l', r'] (l' < l, r < r')$$$ we should use it on segment $$$[l', r']$$$.

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

messed up on C a lot

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

solve() { ll n ; cin >> n; ll a[n+4]; ll mx = 0; ll mn = 1e18; for(ll i = 1; i <= n ; i++){ cin >> a[i]; mx = max(a[i],mx); mn = min(a[i],mn); } ll cnt = 0; vector<ll>v; for(ll j = 1 ; j <= 35 ; j++){ if(abs(mx-mn) == 1){ if((mx>0 && mn > 0) && (mx%2 == 0) ){ v.push_back(1); //cout << "f"<<endl; cnt++; break; } if((mx > 0 && mn > 0) && (mx%2 == 1)){ v.push_back(0); cnt++; break; } //else continue; } if((mx-mn) == 0 ){ break; } mx = 0; mn = 1e18; for(ll i = 1; i <= n ; i++){ a[i] = (a[i]/(ll)2); mx = max(a[i],mx); mn = min(a[i],mn); } v.push_back(0); cnt++; } if(cnt > n){ cout << cnt <<endl; return; } else{ cout << cnt << endl; for(auto x:v){ cout << x<<" "; } cout << endl; } }

why my code is failing . Can anyone give me any case ?

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

Any counter Test for this solution of C https://codeforces.com/contest/1901/submission/234171914

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

In D, won't it be smart to always choose the monster with the highest health at the beginning? I'm unable to come up with a counter-example as to when this won't work

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

    What if there are multiple monsters with highest health?

    Also try this case

    7
    3 1 4 2 2 2 2
    

    If you start with 3, the minimum power is 8 If you start with 4, the minimum power is 9

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

      Thanks for the test case! It makes sense as to why we have to consider every possible index now.

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

    Check out this test:

    8
    1 11 1 1 12 1 1 1
    

    Here, if we choose the monster with 12 health we need x = 17, but if we choose to start from the monster with health 11 we only need x = 16.

    We can't choose the monster with 12 and have x = 16 because we kill that monster and all monster to the right and our power decreases to 12, we kill the monster to the left of it with 12 and we get to 11, we kill the left monster again and we are down to 10, this is less than what we need to kill the monster with 11 health.

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

      2 1 5 6 4 3, in this test case if i choose starting monster as 1 and power as 8 then kill all the monsters to the left the power left is 6 then go left and kill 5 ,then power becomes 5 and then move to left ,now we get stuck at monster 6 because we have only power of 5.then why is the answer 8? or am i making some mistake pls point that out?

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

        The answer is 8 because you can choose to start at the monster 6 and for every option you take at whatever point in time you can always kill all the monsters.

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

          but we are told that the answer should work even in the worst case, so why won’t the case i mentioned be considered.

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

            It should work in the worst case for the starting element that you have chosen, that's why the problem comes down to finding the starting element for which the worst case is the least of all the other worst cases.

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

In this round,Im_dik from Chongqing Nankai Secondary School defeated the famous Legendary Grandmaster Um_nik. It's so fun!

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

I am curious about the input size n (5 times of 10^5 but not usual 1 or 2) in problem E, is it intended? I kept getting MLE and RTE during the contest and, it turns out RTE is stack overflow (I should have thought it through), while I only left two local variables in the usual tree-DP recursive function. After exact those two local variables out of the recursion stack, it is an Accepted code. It seems that the stack size setting for Java in CF is a small number of MB, while I never thought it would be an issue, at least not in tree-DP. (BTW I used 128MB in local dev-environment setting.)

But thanks to this problem, now I have got a snippet of code to do tree-DP-traversal without recursion. =)

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

The system test finished and my tricky solution 234102255 for problem E is still alive. Can anyone provide a hack test or it is actually true ?

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

Waiting for editorial

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

In problem D, for test case 2, 1, 5, 6, 4, 3 why spell of 7 is not the minimum because if we start with index 4(value = 6) and damage = 7, then index = 3 getting damage 6, then index 5 getting damage 5, index 6 getting damage 4 and index 2 and 1 getting damage 3 and 2 respectively. Can anyone suggest where I am doing wrong?

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

    If you start at index 4 with power 7 you than kill the index 5 with power 6 and the index 6 with power 5, now you don't have enough power left to kill the monster at index 4. Remember, since the monster killed is chosen randomly between the 2 options possible (or 1 if there are no 2 possible options), you have to account for the worst case scenario. Sure, power 7 would've worked if you killed index 3 first, then the indexes >4 and than the indexes <3, but that's only one case, we have to account for all possible cases.

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

      so basically if we choose index 'i' so there are two possiblites that either go to the right of till end and the the other half and another one like go to left of i to the start and then go for the other half ?

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

        Those are not the only cases. For example, in an array with 5 elements (1-indexed), if you start at index 3, you can also go 3->4->2->5->1. At any moment in time, if there are 2 indexes that you've not visited adjacent to indexes that you have visited, you can go in either one of the 2, that's why it's important to account for all possible ways. But yes, in the solution, you're basically assuming the worst case scenario, that is, if the index is to the left of the starting element you're assuming it first went to the right and only then came left so that by the time it reaches that index, the power will be the minimum. The same goes for when the index is to the right of the starting index, only in reverse.

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

I have submitted one problem successfully still didn’t get any rate.It's showing unrated..why!!

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

One of the best edu rounds.

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

I Have completed 1 problem successfully still didn’t get any rate.It's showing unrated.why so!!

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

this round is rated or unrated idk. I think this round unrated because rate not given soooo longgg

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

A simple logic for the problem c : if max_element of array is even then we add 1 to array otherwise add 0 234215511

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

I participated this contest but my rating didn't change. Why?

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

will the rate updated before the upcoming codeton contest

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

Has this contest become unrated? It is showing as unrated in ratings graph.

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

Update the rating!

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

Update the rating!

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

update the rating !

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

Please post the editorial.

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

Please Update the Rating !

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

I want to know that if we can solve problem D using priority queue or not ? Here is my submission: https://codeforces.com/contest/1901/submission/234238251

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

Rating Updated! :)

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

Can anyone tell why my D is wrong my approach was to choose the index with maximum value in the beginning and then choose the smallest value which can be reached from that index and also 2 cases which start from beginning and start from end. This is my solution 234114731

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

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

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

I received a notice of violation from the Codeforces system. https://codeforces.com/contest/1901/problem/D for my solution in this problem. But I didn't do anything wrong. How appropriate is this?

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

i see my solution 234103633 and Zephyranthes's solution 234115043 and i don't see any the same to gain the announcement of the system