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

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

Всем спасибо за участие, надеюсь вам понравились задачи! Вы можете оценить задачи раунда в соответствующих спойлерах под разбором.

1798A - Гвоздь программы

Подсказка 1
Подсказка 2
Разбор
Решение
Оценка задачи

1798B - Три семёрки

Подсказка 1
Подсказка 2
Разбор
Решение
Оценка задачи

1798C - Магазин сладостей

Подсказка 1
Подсказка 1.1
Подсказка 1.2
Подсказка 2
Разбор
Решение
Оценка задачи

1798D - Шокирующая расстановка

Подсказка 1
Подсказка 1.1
Подсказка 2
Разбор
Решение
Оценка задачи

1798E - Генератор мультитестов

Подсказка 1
Подсказка 2
Подсказка 2.1
Подсказка 3
Разбор
Решение
Оценка задачи

1798F - Подарки от Деда Ахмеда

Подсказка 1
Подсказка 2
Подсказка 3
Подсказка 3.1
Подсказка 4
Разбор
Решение
Оценка задачи
Разбор задач Codeforces Round 860 (Div. 2)
  • Проголосовать: нравится
  • +262
  • Проголосовать: не нравится

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

Shows me , posted 5 days ago, fastest editorial ??

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

Oh, a tutorial with Python code, how avant garde

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

E can be passed by brute forcing all possible positions to change. Not sure if its provable but I couldn't think of any hack cases when coding it. https://codeforces.com/contest/1798/submission/199283535

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

In Problem D:

Can anyone tell me the ans of test case:

1

5

1 2 3 -30 -20

According to my understanding, the ans should be No, as sum of abs(-30 + -20) > max(3) — min(-30), but many of the passed solutions are outputing Yes

Edit: Got it, forgot to read the very first line of question

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

WoW! The editorial dropped faster than my rating :)

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

WOW! Lightning fast editorial

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

Problem B is very similar to Kahn's algorithm.

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

You can solve C by abusing the fact that LCM grows fast too.

Greedily try to make segments of the same cost. Naive $$$O(n^2)$$$ is to check if you can make the cost for the current range equal to $$$lcm(a[rstart, i])$$$ for every $$$i$$$, but you only need to do the $$$O(n)$$$ check if the value of LCM changes between $$$i-1$$$ to $$$i$$$. If it doesn't change you already know it's possible for the range $$$[rstart, i-1]$$$. So you just need to check if you can include $$$i$$$ in the range. 199293298

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

Did you not include a pretest with n=3e5 in D on purpose?

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

    Also he did not include a pretest with n=2e5 in C on purpose.So my C and D are all hacked haha.

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

The system test of problem E is too weak. My brute force solution passed it, and it can be hacked by a very simple testcase. Please be more careful for preparing testcases.

Link:199296293

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

This was kind of a hope greedy works contest imo.

In both c and d i was like "i hope this covers all cases, let's submit". I don't really like this kind of problems

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

    That's so true man I did the same with C then I could not think about the solution of D so with 5 minutes remaining just coded up whatever came to mind and it got accepted with 15 seconds remaining hehe.

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

      True, turns out that in d you can just assign any valid value and repeat for each element of the array and it's guaranteed to find the solution

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

Please explain C someone ???

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

In C, according to tutorial if we solve for prefixes like:

{[a1, a2, a3] [a4, a5, a6] [a7, a8, a9, a10]} have price tags {c1, c2, c3} and c1 becomes equal to c3. the solution should fail, correct me where I'm wrong.

Edit: I read the question wrong

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

Problem D was easier than Problem C... Is it?

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

(For problem F) I had never heard of the Erdős--Ginzburg--Ziv theorem but I guessed that it had to be true by the fact that none of the samples had "-1" as an answer.

For those curious, an elementary proof is in the second response here.

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

    Why that proof need to reduce the original problem to the case when n = prime?

    Does any step using the property that $$$p$$$ is a prime?

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

This is the fastest system testing on codeforces , nice contest.

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

Did not participate in this round but surely not a well set round. You expect Div2C and Div2D to have a certain difference in difficulty. The D problem surely didn't deserve to be a Div2D.

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

Like these hints.Thanks.

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

anyone provide me problem B c++ code

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

In C problem , wrote the code of LCM wrong. Didnt check as i was taking GCD and LCM for granted. Can't handle more negative. Wanna die :(

Negative delta loading ...

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

Thanks for the problems! Pretty interesting and balanced set.

By the way, it seems we can't view the reference solutions.

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

    lol, indeed, thanks for pointing it out. fun fact is that I copied template from editorial of previous round, and it is impossible to see reference solution in that editorial too, and nobody said that before. that is pretty much proves, that this references are useless, but I'll update them soon.

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

is cf predictor working?

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

Great round, thank you very much problemsetter!

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

How would you do D, if the sum wasn't 0?

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

    Basically the same idea of considering prefix sums works except you have to be a bit more careful. If all the numbers are nonnegative or nonpositive it's clearly impossible. Now, without loss of generality assume the total sum is nonnegative. Let mx be the max element and mn be the minimum element. If the total sum is >= mx — mn, then of course the task is impossible no matter how you reorder the array, otherwise it's possible.

    First, place all the 0s in the array at the front. Then, it is possible to add elements so that the prefix sums are always in [0, mx — mn). Specifically, if the current sum is in [0, -mn), you add a positive element, otherwise if it is in [-mn, mx — mn), you add a negative element.

    This strategy ensure the prefix sum will always be in [0, mx — mn) until we run out of positive elements or negative elements. Then, since the total sum is in [0, mx — mn), adding the remaining positive or negative elements will still keep the prefix sum within [0, mx — mn).

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

Appreciate that the solution has hints. Helps with upsolving problems beyond our range!

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

About the D Problem.

max1≤l≤r≤n|al+al+1+…+ar|

Is there a way to minimize this formula?

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

For B, you can choose the elements that appear the least later on in the future and it also works.

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

The solution link in the problem F is not working. Hope it will be fixed soon.

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

I think the testcases of problem B is weak ? My nearly brute force solution 199278375 passed (1387ms) ,and you can easily find a testcase to hack my code.

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

    Which part is brute force? Learn meaning of it first xD. It is greedy and since everyone can take at most one place, your solution is correct. Getting 1387 ms. because for every test case (5e4), you're clearing your arrays with size 5e5.

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

Really great round

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

Great round and a great editorial indeed. If anyone wants a video editorial for these problems (for Problem A, Problem B, Problem C, Problem D). You can watch this here — video editorial

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

the solution for F can't be viewed.
Also if the complexity for single si is n^3(8000000) and the restriction is 1s, how can this avoid getting TLE?

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

    I pasted my code in editorial. For a more understandable and better written code, I recommend to look into jiangly's submissions (Top1 of this round).

    On practise, this is very very fast $$$O(n^3)$$$ (it can be even improved to $$$O(n^3/w)$$$, where $$$w = 64$$$, with bitset), a lot of solutions fits into 50ms, and also there is Python solution that fits under 200ms.

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

    $$$200^3$$$ is just $$$8*10^6$$$ which is super fast for 1 second on Codeforces' servers.

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

      I didn't notice that the sum of $$$s_i$$$ is no greater than 200. I thought for each $$$s_i$$$ there is a O($$$n^3$$$) dp and the total complexity will reach O($$$n^4$$$)...
      $$$8*10^6$$$ can be done in 1s is pretty fast though

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

E is a beautiful problem

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

In Problem C I don't understand why using GCD and LCM. can anyone explain it in detail? I really appreciate any help you can provide.

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

    let the cost of each pack of candies be $$$C$$$. So, it must satisfy that $$$C = B_i \times D_i$$$ for each $$$ 1 \leq i \leq n$$$.

    Thus, All $$$B_i$$$ must divide $$$C$$$ which means $$$lcm(B_1, B_2,..., B_n)$$$ must divide $$$C$$$.

    Now, $$$D_i$$$ is a divisor of $$$A_i$$$. let, $$$K_i = \frac{A_i}{D_i}$$$.

    $$$C = B_i \times \frac{A_i}{K_i}$$$ for each $$$ 1 \leq i \leq n$$$.

    $$$K_i = \frac{B_i \times A_i}{C}$$$ for each $$$ 1 \leq i \leq n$$$.

    $$$K_i$$$ must be an integer which means $$$C$$$ must divide $$$B_i \times A_i$$$.

    Thus, $$$C$$$ must divide $$$gcd(B_1 \times A_1, B_2 \times A_2,..., B_n \times A_n)$$$.

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

      You are the God Sir. Believe me You explained it so clearly . My whole lifetime i will not forget this(I am not exaggerating.)

      I Wish every tutorial are like this. Thanks a lot sir.

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

For Problem F, the $$$n^3$$$ DP can be instead be done in $$$n\log n$$$ after a recent preprint. See submission 199466476 (assuming I implemented it correctly).

Obviously, this is completely unnecessary.

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

Ok, its 2 days after round, I decided to write a little postscriptum, which can answer some questions and show some insights of problemsetting/testing.

Firstly: thanks everyone who wrote comment with positive feedback about the problems, it's a big pleasure to see it, really. Second: apologize to everyone who got FST and negative delta because of it, pretests quality on problems B, C, D was poor, I'll be more careful with this next time.

Why D is easier than C, is it intended?
Story of problem A
Story of problem B
Story of problem C
Story of problem D
Story of problem E
Story of problem F

Forgive my non-prefect English, but I believe text is still understandable despite my mistakes. Thanks everyone who read that!

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

    Is there any basic proof for why greedy works in C? Still can really believe it or prove it myself

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

      Consider any possible answer and any possible price tag in it. If this price tag can be expanded to the right by 1, lets expand it. Since "If one price tag is enough for a set of candies, then if you remove any type of candy from this set, one price tag will still be enough" this action can not increase number of price tags. So starting from any possible answer we can expand any price tag to the right while we can, and number of price tag will not increase. After we do all possible expands we will achieve greedy construction (in greedy construction no price tag can be expanded to the right. and its unique construction, because there is only way to choose prefix that cannot be expanded to the right, and so on).

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

    Thanks for the editorial, I have a simple doubt, Can you tell me in problem C we are taking lcm(b1,b2...bn) and not lcm(b1*d1,b2*d2...bn*dn). Is that because we are trying to remove di from the picture?

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

Cost of each bag from i to j will be gcd(ai*bi, ai + 1 * bi+ 1,...., aj * bj) (provided the condition stated in tutorial for i to j is satisfied) Or I am thinking wrong? Please someone explain.

Thanks, in advance.

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

    Cost can be any integer $$$x$$$ such that $$$gcd(a_i \cdot b_i, \ldots, a_j \cdot b_j)$$$ divides $$$x$$$, and $$$x$$$ divides $$$lcm(b_i, \ldots, b_j)$$$. So yeah, this gcd is one of the options of cost.

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

For problem E, why is it the case that you only need to check if the dynamics value at i+1 is greater than or equal to a_i? Why don't they need to be exactly equal? In other words, how is it possible to create any number of tests up until the maximum number of tests that can be achieved by changing one element?

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

    Yes, this is fair remark. We can see that if 1 change was made to make $$$x$$$ tests, we can redo it to make exactly $$$x - 1$$$ tests. If first element was changed ($$$i+1$$$) it is pretty clear, we just extend $$$go_{i+1}$$$ to cover one more test. And if not first element was changed, you can change previous element (see picture). So if you can achieve $$$x$$$ tests you can achieve $$$x-1$$$ and so on, recursively, you can achieve any number from $$$1$$$ to $$$x$$$. And since $$$a_i \geq 1$$$ in the problem, its enough.

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

I didn't understand that C should be greedy. Anyone to explain?

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

@sevlll777
In C The word 'cost' is the sum of all costs or the cost of an individual packet.

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

thank you for writing the editorial with hints......

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

https://codeforces.com/contest/1798/submission/245358316 I mistakenly solved the harder version of $$$D$$$ where sum of the elements of the array is not necessarily 0