Official

D - Non Arithmetic Progression Set Editorial by evima


Below, a set is called good when \( y-x\neq z-y\) holds for all triples of distinct elements \(x,y,z\).


[1] The condition rearranged

It is important that we can rearrange the formula as follows:

  • \(y-x\neq z-y\) for all distinct three elements \(x,y,z\) \(\iff\) \( 2y\neq x+z\) for all distinct three elements \(x,y,z\).

This rearranging was also used in several past problems ranging from easy to difficult, such as ARC123-A.


[2] Without the sum restriction…

Let us call an integer \(n\) good when the following holds:

  • when \(n\) is written in base \(3\), all digits are \(0\) or \(1\).

For instance, \(10 = 101_{(3)}\) is good, while \(7 = 21_{(3)}\) is not.

Then, the following property holds:

  • any set consisting of good integers is good.

This is not trivial but is easy to prove after the rearranging in [1].

Let us use the base-\(3\) notation. If \(y\) is good, all digits in \(2y\) is \(0\) or \(2\). Also, if \(x\) and \(z\) are good, there is no carry when calculating \(x+z\). Therefore, \(x+z=2y\) holds only if \(x=z=y\), completing the proof.


[3] Taking care of the sum restriction

A good set is still good after adding the same integer to every element. By using this, the sought set can be constructed if the difference between \(M\) and the sum of a good set is a multiple of \(N\).

Such a good set can be obtained by taking the smallest \(N\) positive good integers whose bottom digit is \(0\) and then adjusting the bottom digits accordingly.

Additionally, in a set \(S\) obtained this way, it follows from the constraint on \(|M|\) that every element is between \(-10^7\) and \(10^7\), so the problem is solved.


[4] Sample Implementation

Python:

n, m = map(int, input().split())
S = []
for i in range(2, 2 * n + 1, 2):
    s, tmp = 0, 1
    for j in range(15):
        if i >> j & 1:
            s += tmp
        tmp *= 3
    S.append(s)
x = (m - sum(S)) % n
for i in range(x):
    S[i] += 1
diff = (sum(S) - m) // n
print(*[s - diff for s in S])

posted:
last update: