Блог пользователя crazyilian

Автор crazyilian, 6 лет назад, По-русски

Это первый наш контест для нас троих (Alexdat2000, crazyilian, sevlll777), поэтому хотелось бы поделиться впечатлениями от создания этого контеста. Если хотите — прочитайте!

ROUND LOG

Ну и, конечно, вот сам разбор раунда.

1358A - Освещение парка
Идея: Alexdat2000

Картинка
Разбор
Решение

1358B - Марья Ивановна нарушает самоизоляцию
Идея: crazyilian

Картинка
Разбор
Решение

1358C - Обновление Celex
Идея: crazyilian

Картинка
Разбор
Решение

1358D - Лучший отпуск
Идея: sevlll777

Картинка
Разбор
Решение

1358E - Вы уволены?
Идея: sevlll777 и crazyilian

Картинка
Разбор
Решение

1358F - Вкусная печенька
Идея: sevlll777 и crazyilian

Картинка
Разбор
Решение от Alexdat2000
Решение от Alivk06 (более короткое)

Спасибо всем, кто участвовал в раунде! Надеемся, что вы подняли рейтинг! А если нет, то не огорчайтесь, у вас всё получится!

Разбор задач Codeforces Round 645 (Div. 2)
  • Проголосовать: нравится
  • -168
  • Проголосовать: не нравится

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

[deleted]

»
6 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится +129 Проголосовать: не нравится
Разбор на русском / Russian tutorial

Another solution to E which seems simpler to me.

Let's call the value of all elements in the second half of the array $$$x$$$.

Let $$$s_k(i) = a_i + a_{i+1} + \ldots + a_{i+k-1}$$$ — the reported incomes.

Pretend there exists such a $$$k$$$ that $$$k\le\tfrac{n}{2}$$$. Consider the following reported incomes: $$$s_k(i)$$$ и $$$s_k(i+k)$$$. Notice that if we double $$$k$$$, the $$$i$$$-th reported income will be equal to $$$s_{2k}(i) = s_k(i)+s_k(i+k)$$$. $$$s_k(i) \gt 0$$$ and $$$s_k(i+k) \gt 0$$$ imply $$$s_{2k}(i) \gt 0$$$. It means that after doubling $$$k$$$, the new value will still be correct. So let's search for such $$$k$$$ that $$$k \gt \frac{n}{2}$$$.

As $$$k \gt \frac{n}{2}$$$, then $$$i + k \gt \frac{n}{2}$$$ holds for all $$$i$$$. It means that all numbers to the right of $$$[i,\ \ldots,\ i + k - 1]$$$ are equal to $$$x$$$.

Notice that if $$$x \ge 0$$$ and some $$$k$$$ is correct, then $$$k + 1$$$ is correct as well, because $$$s_{k+1}(i) = s_{k}(i) + x \ge s_k \gt 0$$$. So if $$$x \ge 0$$$, it's enough to check $$$k = n$$$.

If $$$x \lt 0$$$, we do the following. For all $$$i$$$ we find such numbers $$$p$$$ that $$$s_p(i) \gt 0$$$. Notice that if $$$s_p(i) \gt 0$$$, then $$$s_{p-1}(i) = s_p(i) + (-x) \gt s_p(i) \gt 0$$$. It means that if $$$p$$$ works, then $$$p-1$$$ works as well, so, actually $$$p$$$ can be any number from $$$1$$$ to some limit $$$t[i]$$$. It's easy to find $$$t[i]$$$ using prefix sums array and binary search in $$$\mathcal{O}(\log n)$$$, or use a formula (increasing $$$p$$$ by $$$1$$$ decreases the sum by $$$-x$$$) in $$$\mathcal{O}(1)$$$. If $$$s_p(i)$$$ doesn't hold for any $$$p$$$, assume $$$t[i] = 0$$$.

Finally, notice that $$$k$$$ is a correct answer if and only if $$$s_k(i) \gt 0$$$ holds for all $$$i$$$ from $$$0$$$ to $$$n-k$$$, or, using the precalculated array, $$$k \le t[i]$$$ for all $$$i$$$ from $$$0$$$ to $$$n-k$$$. It means we can just loop through $$$k$$$ from $$$n$$$ to zero and check if $$$k \le \min t[0,\ \ldots,\ n-k]$$$, maintining the current minimum. If the inequality holds, we output $$$k$$$ as an answer. If it doesn't hold for any $$$k$$$, we output $$$-1$$$.

The overall complexity is $$$\mathcal{O}(n \log n)$$$ or $$$\mathcal{O}(n)$$$, depending on $$$t[i]$$$ calculation implementation.

C++
Python
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +230 Проголосовать: не нравится

Good problems, pathetic memes.

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

Need more memes in upcoming tutorials

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

Can someone explain the B?

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

B explanation ?

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

Very good problems! As a participant, I really enjoyed solving this contest! Especially I liked memes in the problems

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

Pictures were amazing!

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

is it possible to solve C using nCk (binomial coefficient) ?

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

i'm in love with those pictures

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

Anyone for TLE/WA uphacking on E? :)

81551641

Edit: Idea is — for x > 0 check k = n. For x <= 0 check shortest, longest, and maximum sum subarrays that contain all numbers in second half. If those 3 don't give a result check all possible lengths that have sum greater than any previous sum for intervals ending at n — 1.

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

When you check the shorter solution of F first ..and wonder this is the shorter one

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

$$$O(N)$$$ solution for B (but it's barely within limits): 81499306

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

    You iterate up to 10^5 for every test case regardless the given N for that test case so your solution is technically 10^5*10^4 for a test where every N=1

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

      Yes, I realised. But after locking my solution. I was disgusted because I also came up with the editorial solution but thought this was better and just quickly submitted. The bright side is that it luckily passed and that now I know CF can handle about 5*10^8 operations in one second (although I won't be relying on it much in the future and will try to make better judgements about the solutions I implement). Good luck :)

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

For problem E, one could also eliminate some values of $$$k$$$ by randomly testing some starting points, then naively test each $$$k$$$ not eliminated: https://mirror.codeforces.com/contest/1358/submission/81552953

UPD: congrats to Kaban-5 for uphacking :)

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

I am still not getting (x2-x1)*(y2-y1) + 1 formula for problem C. like I understand row diff and col diff product gives a number of ways. but why we need + 1 at last. Can anyone explain? thanks in advance :)

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

    The +1 at the end is to ensure the minimum path is included in the answer too.

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

    plz someone explain this..why it is minimum and maximum sum path??

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

      We will go through each diagonal exactly 1 time. The minimum on each diagonal is the upper right cell. And we can go through all of this cells. Similar for maximum.

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

        @ilian04 could u plz clear meaning of "each diagonal" .plz because i am not getting what are u treying to convey by this word? there are just 2 diaginals ??

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

          I was talking about this diagonals. First diagonal contains number 1. Second — 2 and 3. Third — 4, 5, and 6. Etc.

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

            Thanks for this problem. I didn't get it in the contest but I enjoyed thinking about it afterwards.

            I would suggest for next time to put some English text about how exactly the grid was generated (maybe some formal math stuff like $$$i+j$$$ uniquely defines a diagonal or whatever) instead of distracting stories about accounting and "Celex-2021".

            In the contest I didn't make the trivial observation from the picture that each diagonal has increasing numbers (maybe that's my fault, and I'm supposed to infer that from the diagram with the color gradients).

            But I was re-reading the problem statement multiple times looking for some explanation about how the grid was generated, and eventually guessed some random pattern about how the columns and rows have incrementally increasing numbers.

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

For Problem D, I believe you can do in O(n) time. You don't need to use Binary Search, can also use two pointers approach. 81531917

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

amazing tutorial crazyilian !!

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

Can anyone please check my solution out for problem B and let me know why I got TLE

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

For D, you don't need binsearch. You can do a loop by which month you end on where you keep track of the the number of days left in the starting month and do a little casework on how many days you're advancing each loop. This is easier done going backwards.

Complexity: improved from $$$O(n \log n)$$$ to $$$O(n)$$$. Not that anybody really cares about that log factor.

81538134 — Here's my solution in weird, overabstracted Haskell. If, say, three people ask, I might write up a more readable C++ implementation.

EDIT: Apparently arthurg has already done that; refer to his post.

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

Ques A 81487617 Can anyone help I don't get what is difference between my solution and official solution.

official solution says m*n+1/2 whereas i wrote ceil((m*n)/2.0) is there any diff?

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

Link

Can anyone tell me whats wrong in this logic?

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

Я, как автор контеста, хотел бы выразиться по поводу слишком длинных условий, как считают некоторые участники раунда.

С самого начала написания контеста наши задачи были приурочены к каким-то явлениям, вещам, событиям, содержали много отсылок. К сожалению, первые задачи не дожили до сегодняшних дней, так как были отклонены координатором. Но мы поняли, что для нас интересно придумывать истории, какие-то мини вселенные, в которых происходит действие задачи. После одной задачи про изобретение вакцины (которую успешно отклонили), мы поняли, что тема коронавируса сейчас актуальна и стали придерживаться её. Мы понимали, что длинные условия нравятся не всем, некоторые тестеры нам об этом говорили. Но мы считали и до сих пор уверены, что в таком деле как программирование важно и вдохновение, погружение в атмосферу. Мы максимально старались приблизить перевод к оригиналу.

Тема использования коронавируса как объекта фольклора достаточно щепетильная. Мы осознаём всю его опасность, но это не причина накладывать табу на его обсуждение. Ещё ни разу в истории не было проблемы, которая бы решилась благодаря тому, что на неё не обращали внимание.

Надеемся, что, несмотря на длинные условия, вам всё равно понравились задачи и вы получили удовольствие от их решения.

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

In C I put in a redundant condition to check if x1<=x2 and y1<=y2. But this fails certain testcases. Why would that be can anyone help me with this? What could I be missing here. 81523820

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

I would like to recommend everyone (or maybe those who are not into problem-setting) to read round log just to get an idea of how much efforts go down in making a good quality official Codeforces round.

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

Am I the only one who solved D without noticing that the end of the vacation coincides with the end of some month? 81543406

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

sorry to say , after watching picture of problem D it seems like p**nforces !!

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

Please ,Remove the picture of problem D .

its look like ……….

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

Very good explanation for problem C.

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

I wrote a weird randomized solution, but it passes

https://mirror.codeforces.com/contest/1358/submission/81554878

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

Memes in problem statement would have been nice!

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

Я не понимаю решение задачи В.

Ну например, был дан такой массив бабушек: {10, 10, 10, 10, 10}. И получается, что функция сразу остановится на 5 бабушке и напишет в ответ 5? Но ведь предыдущие бабушки тоже не могут выйти, и на самом деле правильный ответ 1.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
In the end, we came up with E, and the old E moved to D.

Thank you, that explains why I found it so hard.

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

How does https://mirror.codeforces.com/contest/1358/submission/81520389 exceed time limit? since max of a is 2*10^5 or just O(2n) how does it exceed TL?? It passed the pretests during the contest, but i saw that after the contest i got it wrong :(

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

crazyilian, в задаче F написано что должно выполняться Y[i]>=Y[i-1], хотя имелось в виду Y[i]>Y[i-1].

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

I solved D using the idea that optimal answer coincides with end of a month. But now I have an issue. Let's say after concatenating 2 arrays to consider the whole array as one year we get 1 2 1 2 1 2 1 2 1 2 1 2 (insert more 1 2 over here)... 1 2 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 2 3 4 1 2 3 4. Now let's say we consider the segment 1 2 3 4 1 2 3 1 2 1 2 3 4 1 2 3 4 (the segment after 5). It ends at 4 right. So if we move this to left by 1 the answer should decrease because then it would not be end of an array(month). But when we shift it to left by 1 we subtract 4 and add 5(see in original array.. 5 is before 1) so in total we end up adding 1 to the answer. So how to we prove that optimal answer should have end of a month when this is failing over here.

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

Is it a problem — the last line in Excel? Ctrl+, and here it is!

For the last column, use Ctrl+.

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

Kudos codeforces team and the authors very fast tutorial and the rating was also updated very soon. I don't think both of these took place so fast ever. codeforces gets better every day.

thank you @MikeMirzayanov.

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

For each of the n ends, let's make a binsearch to find which month contains --------->> its <<--(what is its in this ??)------- left border (k days less than the right one). You can use array ci to check whether the left border lies to the left/in the block/to the right, and use array di to restore the answer.

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

I'm having a hard time understanding test case #14 for problem E

3
1 1 1
908617379176 908617379175 908616031128

We'll need 1348046 ops to pref() 1 1 1 to

1 1348047 908616031128

and 1 op of reverse to make it to

908616031128 1348047 1

and 1 op of pref():

908616031128 908617379175 908617379176

and 1 op of reverse() to be the target array. How come the answer be 1348047?

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

Why isn't Ternary search applicable in D? Isn't the function a point wise supremum of affine and hence convex functions?

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

Those grannies are yelling "Go Corona Go"

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

D can also be solved in O(n)

Link to my submission:
https://mirror.codeforces.com/contest/1358/submission/81557479

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

Это мое решение задачи Е 81526056. crazyilian есть ли у тебя или у кого-то предположение как это сломать? Потому что по-моему почти очевидное решение, которое первым приходит в голову, когда пытаешься запихать. Я не смог придумать тест. Коротко опишу решение, если x>0, то k=n должно подойти, иначе ответ -1. Если x<0, то я проверяю все k при которых сумма на суффиксе будет >0.

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

anyone plz help me to understand problem B ? thanks

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

For problem E I wrote a code which got WA in test 58 but I will share my idea : as mentioned in the editorial if a solution exists so it is >n/2 let's calculate the prefix array sum since in the second half of the array we have same values so we have two cases: either the accumulative sum will increase if value in second hlaf called x is greater than 0 or it will decrease so in both cases the array accumulative sum will either have a suffix(maybe empty) containing only strictly positive values or negative ones depending on the starting index here is my submission

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

Here i have something about problem C, which i was trying to solve but couldn't. First $$$x$$$ is for row and $$$y$$$ is for column.

A path can be seen as this, a binary sequence of length $$$x2-x1+y2-y1$$$, with number of ones equal to $$$x2-x1$$$. How this happens? oky see, when we want to choose a path, we are now in cell $$$[x1,\,y1]$$$ we can go down or right, if we go down then the head(the number on the cell we are, comparing to the number on the last cell we were) will be increased by $$$x+y+1$$$, and if we go right then the head will increase by $$$x+y$$$ so the difference between them is 1, and so it also applies to next numbers. So we have a sequence of ones and zeroes of length $$$x2-x1+y2-y1$$$ with $$$x2-x1$$$ ones(number of times we go down) and $$$y2-y1$$$ zeroes(number of times we go right).

Now the magic begins, two path's sums are different if and only if the sum of suffix sums of they're sequences are different. And so the answer to the problem is the number of different sum of suffix sums a binary sequences of length $$$x2-x1+y2-y1$$$ with $$$x2-x1$$$ ones can get, YAY, we turned our D1A problem to a literally harder problem. Please let me know if you could solve it that way.

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

    Actually i did C the way you described above.

    But after noticing, that when we go to the right, number in the cell will increase by x + y, and when we go down it will increase by x + y + 1. Due to one to one correspondence i replaced it with the sequence we would get, if number in the cell increased by 1 when we go down and stayed unchanged after going to the right.We will concider 2 new sequences distinct if their sums are different. Lets concider a path: once we go down the number in the cell increases, and this 1 will be added up to each cell in path, starting from this cell. So we can calculate the sum of the elements of the new sequence as a sum of l for all l, where l is the serial number(calculating from the end) of the turn we go down from in path. 1 <= l <= (x2 — x1 + y2 — y1) . So our task is reduced to finding number of different sums of x2 — x1 numbers(number of times we go down), where numbers are distinct natural numbers from the segment [1; (x2 — x1 + y2 — y1)]. The smallest possible sum is S1 = 1 + 2 + ... + (x2 — x1) and the largest possible sum is S2 = (y2 — y1 + x2 — x1) + (y2 — y1 + x2 — x1 — 1) + (y2 — y + x2 — x1 — 2) + ... + (y2 — y1 — 1). It is obvious that any sum between is reachable, it means that number of distinct sums is equal to S2 — S1 + 1. Using well known fromulas of summation , we get that answer is (x2 — x1)(y2 — y1) + 1.

    The problem you proposed could be solved similarly. Actually, the sum of suffix sums of your sequence is equal to the sum of elements of my new sequence(see above). (Because if we replace numbers in your sequnce by their suffix sums, we get my new sequence. And new criteria of distinctivity of sequences would be distinctivity of their sums of elements)

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

Another way to visualize the solution to C : Imgur

The difference between max sum and min sum is shown in the last matrix. This difference is sum(green) — sum(blue). Hence total number of sums between the two is (max_sum — min_sum + 1) = 10 for this 4x4 example.

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

    LOL i'm glad that someone else saw it like that, i just needed to find a reliable way to actually calculate it so i wrote out each case on a grid and guessed the answer once i saw the x*y+1 pattern

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

    if it is a rectangle instead of a square?

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

      Take a 3x4 :

      Range of sums is from 0 to 6. Answer: is calculated as the (sum of numbers along green path) — (sum of numbers along blue path) + 1 :

      (0 + 1 + 2 + 2 + 1 + 0) - (0 + 0 + 0 + 0 + 0 + 0) + 1 = 7
      

      Basically, it doesn't matter what numbers are in the rectangle (i.e. x1, x2, y1, y2 are irrelevant. All that matters is x2-x1 and y2-y1). All 3x4 rectangles boil down to the numbers in the third diagram. The path with the smallest sum runs along the blue cells (right on row 1 and then down on column n) and the path with the largest sum runs along the green cells (down on column 1 and then right on row m)

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

    thanks bro for this great visualization but sorry that I am still unable to get how does that make us reach to (c — a) * (d — b) result

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

      The visualization was actually more of the proof and how to think about the solution.

      To get the m * n formula, consider that you have a 2x4 matrix (2 rows, 4 columns), so you can move down 2 times and right 4 times. The smallest sum path is: DDRRRR and largest sum path is RRRRDD. Every other path in between needs to be included. So here are all the paths (from smallest to largest) :

      RRRRDD
      RRRDRD
      RRDRRD
      RDRRRD
      DRRRRD
      DRRRDR
      DRRDRR
      DRDRRR
      DDRRRR
      

      This comes to: (number of downs) * (number of rights) + 1 = 9 for this 2x4 example.

      I had solved it using a different method by counting the number of diagonals and adding their "lengths" (as each diagonal "length" represents the difference between the smallest and largest elements on that diagonal). So the visualization was more pertinent to that solution.

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

    huge thanks bro..i understood

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

crazyilian The solution to problem C: Celex Update contains a (q--) instead of a (t--).

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

So is this balanced ? I mean no graphs and no data structures ?

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

typo in D di=a1(a1+z)2+...+ai(ai+1)2 that must be a1(a1+1) crazyilian

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

ну очевидно почему картинки убрали.коронавирус-чан выглядит совсем не так

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

Problem F can be solved in $$$O(\log^2 C \cdot n \cdot min(n, t))$$$.

It is possible to show that after applying $$$k$$$ operations of "rollback" the elements of $$$b$$$ will change as follows:

$$$b_{i} = \sum_{j=0}^{min(i, k)}(-1)^{j} \cdot \binom{k}{j} \cdot b_{i-j}$$$

This calculation takes $$$O(n \cdot min(n, k))$$$ time.

Instead of applying a list of rollback operations in a row one-by-one, I want to make a binsearch to calculate the maximal number of operations I can apply.

In details, these two conditions must hold if it's possible to apply some number of rollbacks:

  1. All elements of the resulting array must be positive

  2. The sum of all elements must be not less than the sum of elements in $$$a$$$.

It can be proven that while applying rollbacks if at some point a negative element appears in an array, then it will stay there forever.

So, this solution works in $$$O(\log C \cdot n \cdot min(n, t) \cdot R)$$$, where $$$R$$$ — number of reverses in the optimal answer.

If $$$n = 2$$$, $$$R = O(\log C)$$$, hence it holds for the bigger values of $$$n$$$.

In order to overcome overflow problems, the binsearch can work similarly to binary lifting (firstly, we increase the step by $$$1$$$, $$$2$$$, $$$4$$$, ... and then decrease it in the reverse order).

This solution doesn't require separate consideration of the case $$$n = 2$$$.

My code: 81528455

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

E also can be solved using min segment tree with push updates. As In solution k >= n/2, we iterate k from n/2 to n,add x on prefix 0...n-k and check if it > 0 81558894

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

D can be solved by:

  1. Doubling the array d[] and reversing it.
  2. Using two pointers to find the maximal score for any given starting month (this will really be the ending month since the array was reversed) in O(n) time.

81566497

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

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

C. There are six possible unique sums(on the diagram). But why is the answer 5?(2*2+1)

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

Can someone pls explain how is Problem C different from the standard Find number of ways to reach one point from another in a grid which has an answer of (M+N)!/(M)! (N)! after shifting x1, y1, to origin?

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

    take test case (1,1) (3,3) for example

    if you go: right down down right and down right right down, they result in the same sum. thus, you cannot count that.

    instead, take the minimum sum possible (go all right then all down), and then the maximum sum (all down then all right) and subtract them. i wrote out all the test cases (represented as xdelta and ydelta) and guessed that it was xdelta * ydelta after seeing the pattern

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

Great Contest!

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

Why are we not solving problem C in this way Let D1=x1-x2 D2=y1-y2 Ans would be arrangement of D1 no of x and D2 no of y So why we not directly write the ways of d1 x and d2 y Eg D1 is 3x-xxx and D2 is yyy ie 3y So ans is (3+3)! and also there are repeatitions of x and y so (3+3)!/3!3!

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

I have a bit shorter solution for Problem F. The idea is approximately the same as the tutorial. I notice that when $$$n \gt 2$$$, n*t is always smaller than 10^8, so we can implement the $$$n \gt 2$$$ parts together. In my code, I just simulate the first 2000000 'P' operations regardless of n, which I think makes my code neater. Then I deal with n=2 specifically.

My Code

Submission 81693390

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

Thanks a lot for sharing your experience as first-time problemsetters! I'm currently waiting on a proposal I made, so your story helps me know more or less what to expect from the coordinator (patience, more than anything :P). This is specially cool since I've never seen anyone write about their experience with the coordinator or with Mike, they're kind of an unspoken secret throughout setters, so thanks for breaking the ice on that.

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

For problem C, I calculated the actual minimum and maximum sum possible and got TLE for using big integer in C++. My solution This might help in future in such diagonal filling problems if constraints are a little lower. P.S. — I 90% sure my solution gives the correct answer. Can someone give me assurance of 100% or tell me it is wrong for some cases?

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

how is (c — a) * (d — b) giving unique paths in problem C please explain? I think I am a bit weak at p&c so explain in easy language please

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

    Ok let me explain this to u ... may it helps u!! See first of all u go through the first row up to the last coloum (that path of minimum sum). Now all u need to do is that go up to the second last coloumn and move down and go right again and u will see that u are matching with the same path. Now take the same turn for third last column(go down) and then go right staight and then u will be in the last coloumn matched up with the initial path...u will better find this in the editorial .. by doing this u can see that every time u are making change in the (y2 — y1) coloumn and reaching the the last coloumn by going straing right. The same thing can be done for the rows also u will make changes in (x2 — x1) rows. so the number of path would by the multiplication of (x2 — x1) * (y2 — y1) + 1. NOw why +1? because we are merging into the path of minimum sum and we calculated all possible path to merge into it but we haven't count the original path (path of minimum sum) so +1 is for that. EDIT1 — sorry for any grammatical mistake. EDIT2 — see something else if u don't find proper help by this THANKS U

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

That's an interesting editorial and well explained

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

I used 2 pointer for D but it gives WA because of overflow in C++, i tried unsigned long long too 81577649

I think it's overflow because my exactly same python sol is getting AC 81577330.

Can anyone plz tell me where I can improve?

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

I think we could make memes out of these memes.

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

May be there is another solution to D which seems O(n), does not need vector

Idea is sliding window , please see the code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define _for(i,a,b) for(int i=a;i<b;i++)
#define _ref(i,a,b) for(int i=a;i>=b;i--)
#define MAXN 555555

#define ff(i) ((1+(ll)(i))*(ll)(i)/2)
ll n;
ll a[MAXN];
ll sum=0, ans=0,quit=0, x;
int main(){
    ios::sync_with_stdio(0);
    cin>>n>>x;
    _for(i,0,n)cin>>a[i];
    ll l=0, r=0, que=0, quitl=0, quitr=0;
    while(1){
        while(que<x){
            que+=a[r];
            sum+=ff(a[r]);
            r++;
            if(r==n){r=0;quitr=1;}
        }
        while(que>=x){
            que-=a[l];
            sum-=ff(a[l]);
            l++;
            if(l==n){l=0;quitl=1;}
        }
        if(que<x){
            if(l>=1)ans=max(ans, sum+ff(a[l-1])-ff(que+a[l-1]-x));
            else ans=max(ans, sum+ff(a[n-1])-ff(que+a[n-1]-x));
        }
        if(quitl&&quitr)break;
    }
    cout<<ans<<endl;
}
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

https://mirror.codeforces.com/contest/1358/submission/81580601 why is it showing TLE i am using a prefix array but it is showing TLE

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

amazing contest! questions were interesting to solve

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

I just FUCKING don't understand what does the picture mean in D.

funny mud pee

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

D in O(N): I know I'm dumb, Can someone please tell me the problem with my lame attempt to solve D.

https://mirror.codeforces.com/contest/1358/submission/81573541

#include <bits/stdc++.h>
 
using namespace std;
 
long long sum(long long e, long long s)
{
  return (e * (e + 1) / 2) - (s * (s + 1) / 2);
}
 
int main()
{
  long long n, x;
  scanf("%lld %lld", &n, &x);
 
  long long maxDays = 0;
  vector<long long> v(n);
  for(int i = 0; i < n; i++)
  {
    scanf("%lld", &v[i]);
    maxDays = max(maxDays, v[i]);
  }
 
  vector<long long> v2;
  v2.insert(v2.end(), v.begin(), v.end());
  v2.insert(v2.end(), v.begin(), v.end());
 
  int start = v2.size() - 1;
  int end = start;
  long long tx = x;
  long long ans = 0;
  long long h = 0;
  if(maxDays >= x)
    ans = sum(maxDays, maxDays - x);
  else
  {
    while(end >= 0)
    {
      long long diff;
      while(tx && end > 0)
      {
        diff = min(v2[end], tx);
        h = h + sum(v2[end], v2[end] - diff);
        tx = tx - diff;
        if(tx)
          end--;
 
        // cout << "tx " << tx << " diff " << diff << " h " << h << " end " << end << " start " << start << endl;
      }
 
      ans = max(ans, h);
      if(end < 0)
        break;
      h = h - sum(v2[end], v2[end] - diff);
      tx = tx + diff;
      if(start == end)
        break;
      else
      {
        h = h - sum(v2[start], 0);
        tx = tx + v2[start--];
      }
 
      // cout << "tx " << tx << " diff " << diff << endl;
    }
  }
 
  printf("%lld\n", ans);
}
»
6 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится -31 Проголосовать: не нравится

nmsl

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

nmsl

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

I'm having some weird problems with overflow or something at the problem D (i'm new to c++). Does anyone know what could be the problem? (https://mirror.codeforces.com/contest/1358/submission/81592636)

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

I would like to thank 300iq for removing the pictures.

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

I'm having some weird problems with overflow at problem D (I'm new at C++). Can someone take a look? (https://mirror.codeforces.com/contest/1358/submission/81592636)

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

At problem D at test 12, my program doesn't for some reason take the correct numbers of days as input, instead it takes just straight 0s... (https://mirror.codeforces.com/contest/1358/submission/81596666). Does anyone have any idea what could it be, since the program surprisingly works for earlier tests? I'm new to c++.

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

$$$t = O(\sqrt[n - 1]{C(n - 1)!})$$$. What? Using Stirling formula we can estimate, that $$$\sqrt[n]{n!} \approx \frac ne$$$, so whole solution will be $$$O(n^2)$$$

If we apply operation R $$$t$$$ times on array $$$[1, 1, \ldots 1]$$$ of length $$$n$$$ we get that last element equals $$${n + t - 1 \choose n - 1}$$$. I guess you used bound $$${n \choose k} \leq \frac{n^k}{k!}$$$, which works fine if $$$k$$$ is way smaller than $$$n$$$, but is an insane overestimate in our case, when $$$n = 2\cdot 10^5$$$, $$$t = 3$$$

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

    In fact the task was harded before (the limit was $$$10^{18}$$$, not $$$10^{12}$$$), but almost no one solved it so $$$C$$$ was reduced. So we did come up with $$$C_{n+t-1}^{n-1}$$$ which was used in the solution of the harder task. You're right, the complexity is definitely overestimated. We had a smaller bound before which worked well but we didn't have a solid proof, so we used this one. I'll try to prove it and fix the issue.

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

      Is it really that harder? For $$$n \geq 4$$$ largest number of steps before exceeding $$$10^{18}$$$ is $$$1817118$$$, which should be small enough. The only case left is $$$n = 3$$$. Within $$$k$$$ steps of R operations $$$[a, b, c]$$$ transforms into $$$[a', b', c'] = [a, b + ka, c + kb + \frac{k(k + 1)}{2}a]$$$.

      Solving for $$$a, b, c$$$ in terms of $$$a', b', c'$$$ (or substituting $$$-k$$$ for $$$k$$$) we get, that if we run $$$k$$$ reverse operations on $$$[a, b, c]$$$ we get $$$[a, b - ka, c - kb + \frac{k(k - 1)}{2}a]$$$. For the second value we can do basic binary search to find largest $$$k$$$ for which it is positive. Third is bitonic in terms of $$$k$$$, so to find where it is positive we can for example use ternary search to find minimum, and then on interval from $$$0$$$ to that maximal value binary search where it is positive (or use quadratic formula to find this segment).

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

He also suddenly renamed problem F and city in the English version of problem D.

I wonder what was the original version of the city where Coronavirus-chan lives in.

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

I can't imagine what if it weren't 300iq that coordinated the round.

Will you feel good if someone else "just made some cool memes" about Chernobyl?

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

Hey, why isn't the path 1+3+5+8+13 taken into consideration in Problem C ?

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

i think C is more easier than B.. Though C some tricky but easy ❤By applying distance law (without square)+1 ; ****

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

In case anyone need Detail explanation for D Here

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

I'm not sure whether my solution to F is shorter...

Cuz it's a different way of presenting.

#include <cstdio>
#include <algorithm>
#include <cstdlib>
 
typedef long long LL;
const int MN = 200005, MS = 10000005;
 
int N;
LL A[MN], B[MN];
LL Ans[MS]; int C;
 
inline void check() {
	int ok1 = 1, ok2 = 1;
	for (int i = 1; i <= N; ++i) {
		if (A[i] != B[i]) ok1 = 0;
		if (A[i] != B[N - i + 1]) ok2 = 0;
	}
	if (!ok1 && ok2) ok1 = 1, Ans[++C] = -1;
	if (ok1) {
		LL tot1 = 0, tot2 = 0;
		for (int i = 1; i <= C; ++i)
			tot1 += Ans[i] == -1 ? 1 : Ans[i],
			tot2 += Ans[i] == -1 ? 0 : Ans[i];
		if (tot2 > 200000) printf("BIG\n%lld\n", tot2);
		else {
			printf("SMALL\n%lld\n", tot1);
			for (int i = C; i >= 1; --i) {
				if (Ans[i] == -1) putchar('R');
				else {
					int x = Ans[i];
					while (x) putchar('P'), --x;
				}
			}
			putchar('\n');
		}
		exit(0);
	}
}
 
int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%lld", &A[i]);
	for (int i = 1; i <= N; ++i) scanf("%lld", &B[i]);
	check();
	if (N == 1) {
		if (A[1] == B[1]) puts("SMALL\n0\n");
		else puts("IMPOSSIBLE");
		return 0;
	}
	if (N == 2) {
		if (B[1] == B[2]) return puts("IMPOSSIBLE"), 0;
		while (1) {
//			printf("(%lld, %lld)\n", B[1], B[2]);
			if (B[1] > B[2]) std::swap(B[1], B[2]), Ans[++C] = -1;
			if (A[1] == B[1]) {
				LL diff = B[2] - A[2];
				if (diff < 0 || diff % B[1] != 0) return puts("IMPOSSIBLE"), 0;
				Ans[++C] = diff / B[1];
				break;
			}
			if (A[2] == B[1]) {
				LL diff = B[2] - A[1];
				if (diff < 0 || diff % B[1] != 0) return puts("IMPOSSIBLE"), 0;
				Ans[++C] = diff / B[1];
				Ans[++C] = -1;
				break;
			}
			if (B[2] % B[1] == 0) return puts("IMPOSSIBLE"), 0;
			Ans[++C] = B[2] / B[1];
			B[2] %= B[1];
		}
		LL tot1 = 0, tot2 = 0;
		for (int i = 1; i <= C; ++i)
			tot1 += Ans[i] == -1 ? 1 : Ans[i],
			tot2 += Ans[i] == -1 ? 0 : Ans[i];
		if (tot2 > 200000) printf("BIG\n%lld\n\n", tot2);
		else {
			printf("SMALL\n%lld\n", tot1);
			for (int i = C; i >= 1; --i) {
				if (Ans[i] == -1) putchar('R');
				else {
					int x = Ans[i];
					while (x) putchar('P'), --x;
				}
			}
			putchar('\n');
		}
		return 0;
	}
	while (1) {
		if (B[1] == B[N]) return puts("IMPOSSIBLE"), 0;
		if (B[1] > B[N]) {
			std::reverse(B + 1, B + N + 1), Ans[++C] = -1;
		} else {
			int ok = 1;
			for (int i = 2; i <= N; ++i)
				if (B[i - 1] >= B[i]) ok = 0;
			if (!ok) return puts("IMPOSSIBLE"), 0;
			for (int i = N; i >= 2; --i)
				B[i] -= B[i - 1];
			Ans[++C] = 1;
		}
//		printf("\t\t\t"); for (int i = 1; i <= N; ++i) printf("%lld, ", B[i]); puts("");
		check();
	}
	return 0;
}
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I realised that my proof of D was wrong. The proof in the editorial is very nice indeed!

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

In my view, codeforces is a great training platform with high quality problems. Please do not make it politicized.

Thank 300iq for his wise decision!

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

Can someone please explain the two pointer approach for problem D?

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

I can't seem to find the error in my solution so if anyone can spot it: https://mirror.codeforces.com/contest/1358/submission/81631720

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

Why downvotes?

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

Can someone tell me what is the time complexity of my code? https://mirror.codeforces.com/contest/1358/submission/81649608

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

Great work guys, thanks for the contest. It requires a lot of work to host a contests on Codeforces. Problems were really interesting, had fun solving it.

It's sad that editorial is being downvoted so badly after such a hard work by problem setters,testers and codeforces. Hope it gets upvoted!! It motivates problem setters, we get more great contests :)

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

Yet another explanation of E:

  1. Read proof that k > n/2 from editorial (it's nice and simple)

  2. I check every k from n/2+n%2 to n and return the first good k.

  3. I always start at the end with the last k characters. Let's take a look (for simplicity assume that n is even):

t[1],t[2],..,t[n-k-1], t[n-k], base

base = t[n-k+1],..,t[n/2],x,..,x

The base is initially at the end and I will move it to the left. Let's look at the first 2 shifts:

t[1],t[2],..,t[n-k-1], base1, x

t[1],t[2],..,t[n-k-2], base2, x, x

sum(base1) = sum(base) + (t[n-k]-x)

sum(base2) = sum(base) + (t[n-k]-x) + (t[n-k-1]-x)

and so on. We see that the shift by l positions equals to adding a continuous subarray of values: (t[n-k]-x) +..+(t[n-k-l+1]-x) to sum of our initial base. In order to find the worst segment, we should find a minimum continuous subarray ending at an appropriate position (it is a standard subproblem — here we allow empty array).

So we can check if the k is ok by if(sum(base)+worst_subarray[n-k] > 0) in O(1) and we run it for all candidates.

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

    So, you wrote that we need to find the continuous subarray (t[n-k]-x) +..+(t[n-k-l+1]-x). I just wanted to confirm that will the worst_segment be of size l? If yes, then you also wrote that to find the worst segment, we have to find the minimum continuous subarray ending at an appropriate position(doesn't this take O(n) because we have to iterate by sliding window of size l to make sure that size of each segment is l and then take the one that gives minimum segment sum? And if this really takes O(n) then we do this for every possible k from n/2+n%2 to n and later return the first good k.)

    Can I get the link to the above explanation too?

    Thanx in advance.

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

      l is the size of the shift — from the end, we shift l times to the left. The size of the window is k.

      The shift of the window with size k by l positions to the left can be expressed as (t[n-k]-x) + (t[n-k-1]-x) +..+ (t[n-k-l+1]-x) + base. In order to find the worst shift (the position of the window, with the smallest sum) we need to find the smallest continuous subarray ending at n-k. We can pre-compute these values and for each k we find the position of the window in O(1).

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

        ok got you. So, isn't this quite brute force, because we are doing this for k between n/2 to n and for each k we are shifting the window by a total of l positions so isn't the total time complexity equal to O(n/2*l). Can you help in finding the effective time complexity of O(n/2*l). I don't know why I get the feeling that this is O(n*n). If so, can you correct me?

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

          You check each k in O(1). You find the worst shift by adding the minimum continuous subarray (each shift is represented by the continuous subarray, so the worst one is the minimum subarray). You can check my submission.

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

bad memes

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

I wonder whether the writers of this round are idiots.

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

I think the tutorial of problem E is too tedious...

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

    In E's editorial there are some inconsistent statements like "Notice that the minimum reported income (some number from $$$s$$$) doesn't depend on the first element of $$$p$$$", while next sentence says explicitly that if we change $$$p_1$$$ then all of the $$$s_i$$$ would change as well. So these $$$s_i$$$ do actually depend on $$$p_1$$$ while what is meant for $$$s_i$$$ is that its $$$\sum_{j=2}^{i} p_j$$$ part would never change.

    Anyways, do you have some easier solution/explanation?

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

      In my opinion, the first step is the key of this problem and its proof is given in the tutorial.

      Then let K=(n/2)+1 which is the minimum possible k, and then we let b[] = {s_1, s_2, ... , s_{n-k+1}} (s_i means a_i+a_{i+1}+...+a_{i+k-1}). And this can be calculated in O(n).

      Consider how b[] changes when K=K+1. It is obvious that b[] changes into b'[] = {s_1+x, s_2+x, ... , s_{n-k}+x} (or we can say we add b[] by x and remove the last element). Notice that if min_element(b[])>0 we get a valid answer, than we can solve this problem without the tedious mathematical derivation. And I think it is much more intuitive maybe?

      My code: https://mirror.codeforces.com/contest/1358/submission/81881217

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

I just tried to use lower_bound instead of upper_bound in problem D. Still it got accepted. Can anyone explain the reason? Thanks in advance!! Submission--> 81893828

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

r

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

O(logn) solution for B

104247218 If you want explaination comment it and I will

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

nothing funnier than watching nerds make memes about the stuff they find funny