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

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

Good Day Codeforces!

Me, Wansur and Chalishkan are happy to invite you to take part in Codeforces Round 973 (Div. 2), which starts on 20.09.2024 17:35 (Московское время) You will be given 6 problems and 2 hours to solve them. One problem was divided into two subtasks.

The round will be rated for all participants with a rating lower than 2100.

The problems were authored by me, Wansur and Chalishkan to solve and alter them.

We would like to thank:

Score Distribution: 500 — 750 — 1250 — 2000 — 2500 — (2000 + 2000)

UPD1: Congrats to the winners!

div. 2:

  1. EmmaXII

  2. hxano

  3. Muelsyse_sep006

  4. Hexagons

  5. Trumling_hasnotime

div. 1 + div. 2:

  1. maspy

  2. arvindf232

  3. Brovko

  4. aryanc403

  5. E869120

UPD2: The Editorial is out!

It is our team on EJOI 2024 4-th from left is me, 5-th from left is Wansur

We are also very glad that ICPC 2024 will be in Astana, and we wish all participants a good tour!

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

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

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

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

GLHF:)

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

the Score Distribution shows only 1 problem divided into subtasks

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

GLHF

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

as a tester, can say that problems are interesting.GL for all participants

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

АЛҒА ҚАЗАҚСТАН!!!

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

As a tester…

finally, can say it

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

I hope all participate honestly without ChatGPT. Good luck to all!

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

orz

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

I think there should be someone specially for AI Testing and he/she should be mentioned in the blog :)

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

I hope AI is not able to solve any of the problems

»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится
As a first time participant, i want to know
»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится
As a first time participant, i want to know...
»
19 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +65 Проголосовать: не нравится

We would like to thank:

  • Thanks to my cat for touch.
  • Thanks to earth don't kill me.
  • Thanks to the mouse keyboard monitor power cord.
  • Thanks to catGPT trying to replace human.
  • Thanks to me though it did nothing

.. wait to list more

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

Kazakh contest cannot disappoint

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

rip cyan testing

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

As a tester, this round is awesome, and I wish y'all good luck

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

Alga Kazakhstan

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

Hope that would be a lucky round for me.

soullless the best

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

As a tester, i wish you a merry cristmas!

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

hope to get good +ve in this round. Last round problem A destroyed my confidence :(

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

Nah I’d win. Ура мой первый казахский контест!

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

Wansur will win ioi

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

As a participant, soullless and Wansur orz.

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

Hope I'll not lose my rating again QwQ

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

As someone who not a tester, wishing everyone best of luck !

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

I hope the problems are thoroughly tested to be non standard. Thanks for making the round!

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

soullless orz. Hope to get + on this round

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

Чисто казахский контест будет)))

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

А я тоже хотел быть тестером ...

Удачи всем на раунде!

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

As a setter, I wish good luck to participants.

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

Nice hair bro. Gll to all the participants.

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

As an EJOI participant, I can confrim that Wansur and soullless are cool

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

hope pupil will accept me in this round

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

it is required to thank the creators of the internet now

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

Оу да ,Кз Раунд 998batrr покажи как надо писать раунды

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

Return Specialist?

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

KAZAKHSTAAAAAAAAAAAN

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

gl

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

АЛҒА ҚАЗАҚСТАН!!!

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

How to become pupil in a month?

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

How to become pupil in a month?

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

[deleted]

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

No proper thanks to Alan Turing for inventing computers :[

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

is it rated?

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

Wow, it`s 奶龙大头.

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

Wow, this is the big head of the milk dragon.

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

Good luck everyone!

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

expecting a good problemset

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

I wish D is not GPT solvable

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

Technoblade never dies

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

Technoblade never dies

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

i hope i will be lucky.

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

I actually believe that we are not completely powerless in addressing the issues with AI. For example, the following approach could probably work (though, of course, it requires cooperation from OpenAI and cannot completely prevent cheating with AI, but at least it offers an approximate direction): Before a particular contest, CodeForces provides the statements (possibly with editorials) of contest problems to OpenAI. As a result during the contest period, ChatGPT could forcibly reject any requests related to the problems if detected. Through this way, normal AI usage wouldn't be affected, while cheating with AI during the contest could be prevented to some extent. Of course, determining whether a user’s request is related to the problems (to clearly identify where the boundary is, without ambiguous judgement) would still be a challenging issue that needs further exploration, but given the current advancements in AI technology, it is obviously achievable through proper training.

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

    What is the need to provide problems WITH EDITORIAL ?? Why not just problems??

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

      If handled properly, only ChatGPT would be able to access the editorial, which means it would just terminate the conversation as long as it encounters something related to algorithms or logics appeared in the editorial. But as what I've said before, the specific boundary between related or not should be carefully restricted.

»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится
  • Help Dimash find out the password in no more than 2n operations; otherwise, Mansur will understand the trick and stop communicating with him.

No more than 2n operations, but its WA if Im doing exactly 2n operations.

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

why not reminding that there are some interactive problems? I guess you forgot it

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

question 3 is extremely confusing. I dont even get how to take the inputs.

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

I hate interactive problem

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

I hate interactive problem.

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

One of my worst contests, carrot predicts -52 rating loss.

C was pretty annoying, I probably could have solved D if I spent all my time on it, but I ended up splitting my time after A and B on D and C which was a mistake.

:(

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

D solution, please

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

    First, you should have a function $$$f(x, y)$$$ which determines if its possible to have an array $$$a$$$ such that $$$\min(a_1, a_2, \dots, a_n) = x$$$, and $$$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n) = y$$$.

    If you look at $$$f(x, y)$$$ for all values of $$$x, y$$$ from one of the sample, you will have this pattern:

    f =
    00001111
    00011111
    00111111
    00000000
    00000000
    

    Now, you can binary search on the maximum value of $$$\min(a_1, a_2, \dots, a_n)$$$ by querying $$$f(i, 10^{12})$$$.

    Lastly, you binary search on the minimum value of $$$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)$$$ by querying $$$f(\text{min val}, i)$$$.

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

      The double binary search is so ingenious but just too hard to observe, may I ask if there are some similar problems as advice?

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

      I think n time is possible for finding min and max

      For minimum, iterate from start to end while taking sum Min = min(Min,average till that point)

      Same for max only starting from the end to start

      Max = max(Max,average till given point)

      And then answer is max-min

      I will attempt my solution once system testing in done

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

        Insane, how does this logic even work and how did you come up with it ? Would you explain please ?

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

          The idea is pretty simple, you have to minimize the value of ~~~~~ max(a1,a2,…,an)−min(a1,a2,…,an) ~~~~~ The obvious way to do this is, you select the maximum value to be as small as possible and the minimum value to be as large as possible. This will reduce the gap between max and min value and that would be the required solution. Now comes the part where you minimize the value of max, you can do a binary search on answer. Assume you hold a max value, now iterate over the array a, and check if you can achieve this max value in the array. The checking process goes as: if a[i] < (our assumption of max) then just continue as it is already smaller. But if a[i] > (our assumption) then you can simply reduce (a[i] — our assumption) from that and add this value to a[i + 1], and at last if you check a[n] and find it to be less than or equal to our assumption then return true, or else go for a larger assumption. Similar for the case of finding minimium.

          You can check my solution 282139332

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

            How can you guarantee that the case the maximum value to be as small as possible and the case minimum value to be as large as possible happen simultaneously?

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

              The max and min value will always be an element of the array a. I guess you have no confusion regarding this line. Now for an array (a), the max value will always be greater than or equal to the min value. And by any method if we can find the max value then you can obviously find the min value without affecting the max value. Because max and min values are independent of each other.

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

                I don't understand how we can guarantee that the min value do not affect the max value that we can minimize. Like, exist a proof on that? A proof that guarantee that if we modify the array values for reach a maximum minimum, do not affect the minimum maximum.

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

                I don't think it is necessarily true, that max and min will always be the elements of the array, Consider an array [12, 8], Here max and min will come out to be 10, neither one of them is in the array.

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

            Your solution is very interesting. But like others pointed out, I also find it a little unintuitive that the operations you perform to attain the maximum element never worsen the minimum element you can achieve. Does anyone have a proof for this? Alternatively, consider the other solution which has two parameters that control both the max and min and prove the monotonicity of this (as dartvolley did above).

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

      Hey, I think I might have found a small mistake in your comment. $$$f(x,y)$$$ follows the pattern you described if you define $$$x$$$ as $$$\min(a)$$$ and $$$y$$$ as $$$\max(a)$$$, not $$$\max(a)-\min(a)$$$.

      For those interested, here's a proof for the monotonicity of $$$f(x,y)$$$.

      Going by the above definition, $$$f(x,y)$$$ is $$$1$$$ when it is possible to transform $$$a$$$ to satisfy $$$x \le a_i \le y$$$ $$$\forall 1 \le i \le n$$$.

      I make the following two claims:

      1. If $$$f(x,y)$$$ is $$$0$$$, then $$$f(x+1,y)$$$ is also $$$0$$$. If any $$$a_i$$$ was $$$ \gt y$$$, then both outputs would be $$$0$$$. So assume that $$$a_i \le y$$$, then $$$\min(a) \lt x$$$ directly implies that $$$\min(a) \lt x + 1$$$.

      2. If $$$f(x,y)$$$ is $$$0$$$, then $$$f(x,y-1)$$$ is also $$$0$$$. The proof for this is symmetric.

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

for people who got ac after wrong answers: what's a corner case test case for F1?

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

funny problem C. I really feel dumb actually

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

Did only one question, feeling demotivated, again.

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

I could only come up with a solution to solve C with 2n + 1 queries ugh. Couldn't come up with a way to get it to 2n in contest time. https://mirror.codeforces.com/contest/2013/submission/282098849

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

    I have another approach that would still generate 2n + 1 queries in worst case scenario. If you construct the correct suffix by taking up to 2 queries, then you figure out it is the end by 2 queries failing so it takes 2 * length_of_suffix + 2, then can solve for prefix in length_of_prefix queries, and it is required that 2 * length_of_suffix + 2 + length_of_prefix <= 2 * N. But if N = 5, and length_of_suffix = 4, and length_of_prefix = 1, then 4 * 2 + 2 + 1 = 11. Unless this is wrong somehow.

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

      it cannot happen i guess. for something like that to happen we may suppose that we're querying 1 first and 0 later. so in order to get 8 queries to get the suffix and then 2 to check if the suffix is done or not the suffix has to be nothing but $$$ 0000 $$$. and then the first character has to be 1 to get to 11 queries according to you. but since we're asking 1 first, we will start from $$$ i = 0 $$$ and not $$$ i = 1 $$$

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

      One query is sufficient for the first character because if "1" is not a substring, you don't need to check "0" — the string must be only "0"'s.

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

        Wow thanks I didn't see that, yeah that get's accepted with 2*n queries at most cause now it is 1 + 2 * (suffix_length — 1) + 2 + prefix_length = 3 + 2 * suffix_length — 2 + prefix_length = 2 * suffix_length + prefix_length + 1 <= 2 * N, even in the scenario that prefix_length = 1. If prefix_length = 0, then suffix_length = N and 2 * (N — 1) + 1 = 2 * N — 1 <= 2 * N https://mirror.codeforces.com/contest/2013/submission/282136094 I just had to add this line of code to get accepted for adding first character. if (ask(s + '0')) { s += '0'; } else { s += '1'; }

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

Was D really that easy?

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

Buffed versions of problem C: here and here.

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

I would love to learn the intuition behind problem C. I tried to build a solution based on previous guess information but it became confusing to combine all this information into an educated guesses.

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

    first check if there is a '0' in the string. if there isnt, then its obviously just n 1s. so lets assume there is a 0. then we can just start guessing what is to the left of the zero and what is to the right of the zero. check out my submission for details, i think its pretty straightforward

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

Good contest, expecting to reach Pupil.

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

You guys didn't mentioned for interactive why :(

Its my fault also I should have solved B from my first thought only I fcked it up due to overthinking

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

Was E intended to be greedy (pick the smallest number first, then repeatedly pick the next number which will minimise prefix GCD until prefix GCD = array GCD)? Or is that solution hackable?

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

    Than correct :(

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

    I also solved it that way.

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

    I wrote a DP solution in order to avoid greedy solutions which can not be proved. Here is my submission.

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

    I also did that without proving XD

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

    This is correct.

    For example, let the optimal solution be b1, b2, ..., bi, ..., bn where bi is the minimum. Then consider bi, b1, b2, ..., b_(i-1), b_(i+1), ..., bn. Note that gcd after b_(i+1) is the same so we can ignore the sum of that part. Then if b1 > bi, then we have gcd(bi, b1) <= b1 — bi since gcd(bi, b1)=gcd(bi, b1-bi). Hence in our modified solution, the gcd sequence look like bi, <= b1 — bi, <= gcd(b1, b2), <= gcd(b1, b2, b3), ... and the original look like b1, gcd(b1, b2), gcd(b1, b2, b3) It is clear that sum of our modified sequence is better so taking minimum as first is optimal.

    For the recursive part we simply reduce the problem by taking gcd(bi, -) with the rest of the numbers. It is clear that this correspond to the subproblem of the sum of the rest of the gcd sequence and the sum is the same.

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

how to solve D or why my code D Runtime Error ? Thank 282102762

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

Could solve only 1 in my 1st contest. But still, eagerly waiting for the editorial.

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

Problem C is nice, I faced the same problem at OII 2022 but 2*n queries were enough to get only 40 points. (https://training.olinfo.it/#/task/oii_dna/statement)

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

Is there something wrong with my logic for problem D:

Lets use ternary search for lower bound t1 to find minimum (t2-t1) where t2 is optimal upper bound for given t1. It's not hard to show that declared function is convex.

For each t1 lets use binary search to find minimal t2 so that you can readjust array between t2 and t1

For each (t1,t2) we can check if we can fit array into [t1, t2] going right to left one time.

Complexity should be O(log(Max)^2*ArraySize) which should be ok for given values. But for some reason I got Time Limit Exception. Is there flaw in the logic, or I just make a mess with terrible constant? Submission

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

what's edge case in pretest 2 for F1

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

finally for the first time i am into 5000 ranks....... long way to go

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

How to solve B?

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

Saw my first ever interactive problem, panicked, but eventually did it when around 3 minutes were left. Feels good.

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

accumulate(a.begin(), a.end(), 0L) - 2 * a[n - 2] why this not working for B

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

For D, I tried to find the minimum and find the maximum using binary search on difference. Looking at others' solutions, many have computed min and used same idea to compute max by going in reverse. However, I got WA upon doing this. This is the relevant of calculating the min in the array. What am I missing:

    auto ceil_div = [](long long x, long long y) -> long long { 
        return x / y + (x % y > 0);
    };

    auto get_min = [&]() {
        long long mn = a[0], excess = 0;
        for (int i = 1; i < n; ++i) {
            if (a[i] < mn) {
                if (a[i] + excess >= mn) {
                    excess -= mn - a[i];
                } else {
                    long long steps = ceil_div(mn - a[i], i + 1);
                    mn -= steps;
                    excess += a[i] + steps * i - mn + i * steps;
                }
            } else {
                excess += a[i] - mn;
            }
        }
        return mn;
    };
»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

I got D in the last 5 minutes :D, specialist woohoo!

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

It's interesting that most of the people seem to have used binary search for D. I actually solved it by realizing that the optimal array in the end can be made non-decreasing and this way the min_val in the end is just the minimum over all floor(sum[0..i]/i) and max_val is the maximum over all ceil(sum[n-i..n]/i). https://mirror.codeforces.com/contest/2013/submission/282089570.

Not sure if this was intended or I will get a WA in system tests

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

skip PC and doing PD then failed :(

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

How to prove the greedy solution of E?

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

    Let $$$A$$$ be the smallest possible gcd with the current prefix gcd, and let $$$B$$$ be the optimal one, with $$$A \lt B$$$. Then, if we take $$$A$$$, then $$$B$$$ and continue in the same way as in the optimal case, the result will not be worse, since $$$A + gcd(A, B) \le B$$$.

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

      Just in case it's not obvious where $$$A + \gcd(A,B) \leqslant B$$$ comes from, note that $$$\gcd(A,B) \mid A$$$ and $$$\gcd(A,B) \mid B$$$ which means $$$\gcd(A,B) \mid (B-A)$$$ since we have $$$A \lt B$$$ and a divisor of a positive integer must necessarily be $$$\leqslant$$$ than that integer, so we have $$$\gcd(A,B) \leqslant B-A \implies A + \gcd(A,B) \leqslant B$$$.

      Brilliant proof btw!

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

        im really confused can u please help me with this, wtf is A and B, and why do the gcd(A,B) it seems totally unrelated, is do A and B share the same sequence (for gcd) or are they fundamentally different?

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

Just a request:

Please mention beforehand whether there is an interactive problem. Newbies like me will benefit a lot.

I would have opted out of the contest because I did inevitably lose time in my futile effort on the interaction rather than the algo crux. I would have not registered had I known beforehand of the presence of interactive problem(s).

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

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

Is there an issue with AtCoder's Library's lazy segment tree? Or did I improperly use it. I would appreciate any advice anyone can give. Because I tried using ACL's lazy segtree in problem D and got WA. The exact same code but with AI.Cash's lazy segment tree (from here) passed the pretests.

I was able to stress test and find out a test case that the code with ACL's lazy segtree failed on.
1
4
5 1 3 2

Expected Output (in my opinion): 1

Submission that passed pretests: 282094170
My WA submission: 282066742

Cleaned code (without debugging lines and comments):
Pretests passed code
WA code

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

Can anyone explain the logic of problem C?

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

    Sure, ill explain my approach (this is rushed so no fancy LaTeX sadly)

    essentially, this problem, if youve ever seen ioi 2018 d1 p1 (combo), is a lot like that, even in its statement it bears heavy resemblence. But in addition to that, this one is a binary string

    Now if we think of a naive greedy approach, we can notice that

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

      greedy can be optimized easily to get $$$ \lt = 2n $$$ queries. You realize that once we reach the end of the string, elements on left have to be either 1 or 0. So we don't we need to ask two times. We can only ask if its $$$ 1 + suffix $$$ or not. if it is then the suffix increases by 1 on left otherwise increases by 0 automatically

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

Good problems, binary search idea in D was pretty good, tried something similar for the first time

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

good problemset

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

is it just me who felt this contest was significantly easier than the last one? i only solved A in the last contest but i was able to solve AB and got the logic for C very quickly (couldn't solve C because i had never solved interactive problems before, so i struggled with converting the logic to code)

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

What a greedy round.

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

C my first interactive problem and damn how I hate interactive problems now. Anyway anyone got solution of D. My code was like this:

Spoiler

It is pretty straight forward as can be seen but obviously it is wrong and more obviously it did not work. So anybody can tell me what could be the correct approach and how to avoid this infinite loop problem will be much appreciated. peace

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

In Problem A, In the input statement, the meaning of x and y was switched, which caused me one wrong answer. Please review.

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

could anyone provide edge cases for F1? i am pretty confident my soluton is right, but i am still getting WA even after debugging. link

nvm, found the edge case

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

Am I the only person who used prefix sums for D?

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

    How did you solve it using prefix?

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

      Minimum element = min(P[i]/i) where P[x] is sum of first x elements.

      Maximum element = max(ceil(R[i]/i)) where R[x] is sum of last x elements.

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

        Can you please explain why this works and the intuition behind it? I thought of doing something something similar after realizing that the overall sum of the array doesn't change after operations but couldn't get the actual solution.

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

          It is because we if you think you can actually shift a +1 from the left to right and -1 from right to left,

          lets just say we have

          [3,1,1,10,10,10]

          1. when we are at index 1 we cannot shift any bit from left as there is nothing
          2. when we are 2 we can see that we can shift 1 bit ahead to make [2,2,1,10,10,10] => (3 + 1) / 2;

          so like this at any given index we can find the minimum like this by traversing the array from left to right and taking always the minimum og the average till there.

          and same we can iterate a from right to left to find maximum

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

            great intuition, but how were you sure this would work like when i was trying to figure that out I couldnt really get why this works

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

            so how would this work for [1,3]? if i understood correctly, this approach would say that the minimum is 2, while it is actually 1, since the 3 cant be reduced. sorry if i misunderstood the explanation

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

              ya that what i said at any current index you are calculating the minimum by just looking at the average till that index

              for [1,3]

              1. minimum will be set to 1 as average till 1 is 1
              2. minimum will still remain 1 as it was set earlier to 1 even if now the average is 2.

              note we cannot back propagate a +1 so at any current index we can either make the average decrease by 1 or make it same and we have to decrease maximum and increase minimum for our optimal answer we will just calculate the minimum till that index.

              similarly you can calculate the maximum by either traversing from last or reversing the array,

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

          Just try to equalize all elements in array.

          For any two elements i,j where i < j and a_i > a_j. Simply imagine pushing one from a_i to a_j (Do one operation of all k where i <= k < j). Repeat until array is sorted. The Psum method is the efficient way to calculate min/max.

          The proof that psum works is through induction.

          Obviously, we can equalize any singular. element of the array, by doing no operations, and we can near-equalize(max-min = 1) a subarray of elements that are a a a b b b where a>b, by simply decreasing each a and increase each b.

          Now lets assume we have equalized the first k elements where p[k]/k = a, and the exists a l where p[l]/l = b and b<a. We can equalize the next l-k elements, through the inductive structure we are building. So, this results in the subarray aaabbb, which we have proven we can equalize.

          The proof for the max remains an exercise to the reader, but is VERY similar to the min.

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

            Hey, Can you please once look at this code of E and try to find why it's failing for a hidden case -> 282135524

            Logic -> I will get the minimum gcd possible in every iteration

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

            For maximising the minima, I tried to greedily increase each element without lowering the current maximum minima till the ith index by trying to make it equal to the average till now (only possible if avg was higher than element at i) doing so may result in increasing the minima but never lower it. We dont make it more than the avg since it risks decreasing the global minima till now without ever increasing the global minima. We also dont leave it lower than the average since we always can make it equal to the average guaranteed to not reduce the global minima. If the avg was however smaller than element, then then we would leave it as is and take care of it in future iterations as the elements which gets decreased when an element is increased to its avg. I did it separately for the maxima and subtracted the and to my surprise it was AC lol.

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

        I did the same thing

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

        omg what a great solution, i was so close to this did the exact same for the minimum but was not able to come up that we can do the same for maximum.

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

    I used prefix sum too. The first thing that came to mind was binary search on looking at the constraints.

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

I get burned by i32's every time :(

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

A B C Tutorial in Bangla

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

How did you solve E?

I don't know why "the sum of $$$\max(a_1, a_2, \ldots, a_n)$$$ over all test cases does not exceed $$$10^5$$$" at all.

My solution is very sample. This is my code: https://mirror.codeforces.com/contest/2013/submission/282110416

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

    E can also be solved using dp. Let A = max(a[1],...,a[n]). dp[i][j] denotes minimum gcd(a[1])+...+gcd(a[1],...,a[i]), gcd(a[1],...,a[i]) = j. We should only consider i <= log2(A), since it is optimal if gcd decreases at the beginning and it can decrease at most log2(A) times. j <= A. Transitions are as follows : dp[i][j] = dp[i-1][j*k]+j if there exists some a[l], such that gcd(a[l],j*k) = j, k is some constant 1 <= k <= floor(A/j).

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

      "if there exists some a[l], such that gcd(a[l],j*k) = j." How do you check this quick enough?

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

        gcd(a[l],j*k) = j => gcd(a[l]/j,k) = 1. Let's maintain cnt[i][j] meaning number of numbers x, such that x is divisible by i and x/i is divisible by j. Now, a[l] such that gcd(a[l],j*k) = j exists IFF M(d1)*cnt[i][d1]+M(d2)*cnt[i][d2] +...+M(dm)*cnt[i][dm] > 0. M denotes Möbius function. d1,d2...,dm are all divisors of k. We can calculate cnt in O(nlog^2(n)).

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

In problem F1, can someone explain why the answer for this test case is Bob:

8
1 2
1 3
1 4
1 5
1 6
1 7
2 8
2 2

My logic is that Alice can go 2 -> 1, then Bob can only move to 8, then Alice moves 1 -> 7, and Bob can't make a move so Alice wins.

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

Could someone help me proving the TC of this solution in Problem D?

Every iteration I convert all the decreasing subarrays to their almost-equal values with the same sum.

I keep doing this until no operation changes the current array. I can't think of proper upper bound for this solution.

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

Great contest :)

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

Can Someone Please Help me with solution of problem C, which causes TLE 282128399 Thankyou

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

Hey friends! Does anyone know why I am getting TLE on test 1? 282130372 I know my approach is incorrect, but I'm just trying to figure out the TLE. If you cast ans.length() into a long long it works, but I'm not sure why it doesn't otherwise.

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

    As I mentioned in the comment above. TLE is in fact a WA verdict. Because you are given $$$-1$$$ as a response and the program should terminate after. So, treat TLE here as WA or you could just assert that $$$n$$$ is not $$$-1$$$ before proceeding into your logic

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

      Ah I see, so n could be -1 as well, that makes a lot of sense. Thanks for your help!

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

        If you make an incorrect attempt or exceed the limit of 2n attempts, you will receive −1 instead of an answer and get the verdict Wrong answer. In this case, your program should terminate immediately to avoid undefined verdicts

        Honestly, It's my first time facing such issue in interactive problems. But it's good to learn :)

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

First time solved an interactive problem in a contest..feeling good

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

Rating Prediction

A — 800

B — 900

C — 1500

D — 1800

E — 2100

F1 — 2600

F2 — 3100

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

Never thought I would be in the leaderboard of a contest ever! Thanks a lot

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

6k people solve C? That's imposible. People are cheating in current contests.

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

Looks still no editorial yet. This is my unofficial editorial.

A
B
C
D
E
»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +55 Проголосовать: не нравится

Looks still no editorial yet. This is my unofficial editorial.

A
B
C
D
E
»
19 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

My submission: 282147053

Can someone please explain why the following approach works for C-Password Cracking?

Start with an empty string query = "".

Finding the longest suffix:

1s. Guess query + '0'. Yes -> {goto 1s} No -> {goto 2s}

2s. Guess query + '1'. Yes -> {goto 1s} No -> {longest suffix found; goto 1p}

Finding remaining prefix

1p. Guess '0' + query. Yes -> {goto 1p} No -> {goto 2p}

2p. Guess '1' + query. Yes -> {goto 1p} No -> {query is the password}

Up to this point, I know that this approach may take $$$2n + 4$$$ queries at max ($$$2*n$$$ for each character, 2 when the longest suffix is found and we query by appending '0'/'1', and 2 for the prefix similarly.

Improved approach: I maintained two vectors of strings yes and no. Each time I get 1 as a response, I put query inside yes, else into no. Before querying, I put the following checks:

  1. query.size() <= n

  2. every substring in yes must be a substring

  3. no substring in no should be a substring

In this case, I can see that the extra 2 queries for prefix will be cut off leaving $$$2*n + 2$$$ at max. However, this approach has passed all test cases, so queries are reduced to $$$2*n$$$ at max. How?

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

    When you change from suffix to prefix, you can actually be sure the next character that is added to the start of the string is not the same as the first character as you current string. For example:

    0: 1

    00: 1

    000: 0

    001: 1

    0010: 0

    0011: 0

    Here, because 000 is not a substring, the longest contiguous substring with all 0 is only of length $$$2$$$, so guessing 0001 is not needed at it has three consecutive 0. When you check if the no substrings are actually not in your queries, you saved the wasted query of 0001 in the above example, which means this lowered the queries by $$$1$$$, as now you only need $$$1$$$ query for the first time checking prefix).

    Also, in the query of size $$$1$$$ strings, you either get 1 when you query 0 (which means the first character only take $$$1$$$ query, cutting another query from the total), or you get 0 for 0 and 1 for 1 (which means the string is all 1 and ended with $$$n+1$$$ queries)

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

Just now I solved D by guessing, but I couldn't prove my solution. Can someone tell me why the following approach works?

Find the highest possible min using the operations, find the lowest possible max using the operations, then the answer is just lowest_max - highest_min.

Intuitively, it makes sense to me the fact that when using the operations to maximize highest_min you don't violate the operations used to minimize lowest_max, but I can't definitively prove it. Link to my submission.

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

    what did this row k = max(0, k — diff)?

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

      Well that is just implementation detail. Basically the operation can be rewritten to "choose i and j and move any amount from arr[i] to arr[j]" and k is amount of operations we've done to get all arr[i] so far to become mx (or mn in the case of checkmn), but haven't picked the index j to move it to. So every time we meet an element that already satisfy mx or mn we treat it as arr[j] and want to deduct as much from k as we can.

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

    Check this and this out. Using these, you can see that choosing the maximum does not change which minimums are possible to obtain and vice-versa.

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

It was a really good and varied contest. But we are waitting the tutorial.

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

Can anyone tell me why problem F1 WA on 11?

My submission:https://mirror.codeforces.com/contest/2013/submission/282168778

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

Problem F1: My solution fails at 1326th test case of test point 2. see 282161893

I just simulate the game process by finding what next nodes the current player could reach by bfs, and block these nodes from now on. The one who can not reach any new node fails the game.

Could you give me a hack case, or is there something wrong with my code? Thanks a lot!

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

My solution to E that doesn't use "greedy":

  • First find $$$d = \gcd(a_1, a_2, ..., a_n)$$$, then transform $$$a_i \leftarrow a_i / d$$$. We will work with this new array $$$a$$$ and just multiply the result by $$$d$$$.

  • Realise that because $$$\gcd(a_1, a_2, ..., a_n)$$$ is now $$$1$$$, the prefix $$$\gcd$$$ must go to $$$1$$$ sooner or later.

  • Imagine we have arranged the array optimally, let $$$g_i = \gcd(a_1, a_2, ..., a_i)$$$, then the answer is $$$g_1 + g_2 + ... + g_n$$$, or we can write it as $$$n + \sum_{i = 1}^{n}{(g_i - 1)}$$$.

  • Realise that if $$$g_i = 1$$$ then $$$g_{i + 1} = 1$$$, so once $$$g_i = 1$$$ then we don't have to care about later elements because they don't contribute at all to the answer.

  • Which mean to choose the optimal sequence, we want start from some $$$g_1 = a_i$$$ and go to some $$$g_i = 1$$$ with the lowest cost possible, where from $$$g_i$$$ we can go to $$$g_{i + 1} = \gcd(g_i, a_j)$$$ with some $$$a_j$$$.

  • The cost is just the sum of the elements $$$g_i$$$.
  • There might be some concern about using a number $$$a_i$$$ multiple times, but we can see that it's not a problem:
Proof

So now we can try to find the best way to go from each $$$g_1$$$ to $$$1$$$, and we will do this with dynamic programming:

  • Let $$$f[x]$$$ be the minimum cost if we start from $$$g_i = x$$$ and want to get to $$$g_j = 1$$$.
  • Then $$$f[x] = min(f[y] + (y - 1))$$$ for each $$$y$$$ where we can find $$$a_i$$$ such that $$$gcd(a_i, x) = y$$$.
  • The answer will be $$$min(f[x] + x - 1 + n)$$$ for all $$$x$$$ where we have some $$$a_i = x$$$.
  • To calculate this, we have to find the possible $$$y$$$ values for each $$$x$$$ or vice versa.

In my solution, I find $$$x$$$ for each $$$y$$$ like so:

  • Let's count how many $$$i$$$ exist for $$$x = py$$$ such that $$$y = \gcd(x, a_i)$$$.
  • $$$y = \gcd(x, a_i) = \gcd(py, qy)$$$ where $$$a_i = qy$$$ and $$$gcd(p, q) = 1$$$.
  • So for each $$$y$$$, we find all possible $$$q$$$.
  • And then we count for each value $$$p$$$ from from $$$1$$$ to $$$q_{max}$$$, how many coprime number with $$$p$$$ we have.
  • Then for each $$$x = py$$$, we just need to check if $$$q$$$ exists.
Coprime counting

Let $$$k = a_{max}$$$, the final solution is as follow:

  • Iterate $$$y$$$ from $$$1$$$ to $$$k$$$.
  • For each $$$y$$$, find all possible $$$q$$$ where there is $$$a_i$$$ such that $$$a_i = yq$$$.
  • Perform the coprime counting on values from $$$1$$$ to $$$q_{max}$$$. Note that $$$q_{max} \leq \frac{k} {y}$$$.
  • Then update $$$f[x] = min(f[x], f[y] + y - 1)$$$ for each $$$x$$$ such that $$$x / y$$$ has some coprime numbers. Note that $$$x \leq q_{max}$$$.

The iterating $$$y$$$, finding $$$q$$$, and updating $$$x$$$ is done in $$$O(k\ln(k))$$$.

The prime counting is done in at most $$$\sum_{i = 1}^{k}{O(\frac{k}{i} \ln(\frac{k}{i})})$$$. This is a bit complicated, but it should be $$$O(k \ln(k)^2)$$$.

My implementation: 282179720 (pretty much the same as the one in contest but cleared up to use the same variable name I used in this post)

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

    This looks a bit complicated considering an $$$O(n^2)$$$ solution passes AC

    https://mirror.codeforces.com/contest/2013/submission/282184391

    This just starts from $$$gcd$$$ being mininum $$$a_i$$$ and on each iteration find next minimum $$$gcd$$$ with all remaining elements in $$$a$$$ and sum these $$$gcd$$$s in $$$ans$$$.

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

      That is O(NlogN). gcd's prime factorization will consist of at most logN numbers and each time finding the next minimum gcd will remove at least one of those numbers. Your code will loop through array at most logN times until gcd becomes 1 and it will stop. Thus it's N logN

      That aside, the point of the comment you're replying to is to describe a method that we can use precisely to avoid this approach if we can't prove it.

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

        Considering nested loops is the first thing that comes to mind isn't this problem too simple for E on Div.2?

        During contest I discarded this approach as too simple, thinking it was a bait of some sort.

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

          Well based on the fact many skipped D to solve E, probably many people will agree with you. But yeah it is definitely quite straightforward, even compared to some Div 2 D in the past.

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

where is the editorial? (cry emoji)

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

Editorial ?

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

why is this giving Idleness limit exceed 282218277

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

C can be solved with $$$2n-1$$$ operations.Just by starting with "? 01" and "? 10" when $$$n \gt =2$$$.

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

soullless please give the editorial

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

Still waiting for the editorial

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

Customary thanks to Dominater069 for solving the contest and providing his clean and consise solutions.

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

Hi, I have been flagged by the system for my solution to problem E. I ensure that the code was written by me, in a private environment. The logic is quite simple and similar to few grandmasters as well. Kindly help with this issue. I have been a trustful participant. I have also tested rounds on CF, with few coordinaters knowing me. I am happy to provide any more evidence. Thanks! MikeMirzayanov

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