Codeforces и Polygon могут быть недоступны в период с 23 мая, 7:00 (МСК) по 23 мая, 11:00 (МСК) в связи с проведением технических работ. ×

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

Автор abcdef6199, история, 8 лет назад, По-английски

Given an array A of size N. You have to perform K operations. Each operation is:

  • Create a new element equal to the current number of elements.

  • Decrease other elements by 1.

  • Any element that is decreased to 0 will be removed.

  • After that, sort the new array.

Example:

8311 -  > 742 -  > 6331 -  > 5422.

You need to find what the array will be after K operations.

Contraints:

  • 1 ≤ Ai

  • sum(Ai) ≤ 100

  • K ≤ 109.

I feel like this's gonna be a cycle detection problem. I've tested a few cases and I see that the cycle length is quite short. But I have no idea what the upperbound will be.

It'd be great if someone can help me prove an upperbound for this, or give me a testcase where the cycle length is large.

Thanks in advance !

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

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

The sum is constant through the process so every array is a [partition](https://en.wikipedia.org/wiki/Partition_(number_theory)) of sum. The number of partitions for 100 is about 2·108. Real bound is smaller because not all the partitions can occur: for example, it is easy to prove that after 100th iteration all the numbers are smaller than 20 and the length of array is smaller than 20.

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

    Could you tell me some hint about how to prove that "After 100 iterations, the length and the maximum value are less than 20"? I tried to prove it but.... Thanks in advance.

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

    Some hints, please :( I tried to prove it but I can't :( Thanks.

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

    I guess I saw this as a theoretical problem in the past...But I really can't remember what was the exact statement and what was the solution...

    So I think it should be a better bound on this problem...

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

According to this paper the length of every cycle is