#P5379. Alice and Bob Game on a Cyclic Integer Sequence
Alice and Bob Game on a Cyclic Integer Sequence
Alice and Bob Game on a Cyclic Integer Sequence
Alice and Bob play a game on a cyclic integer sequence. You are given a sequence (S) with length (N) (indexed from (0)) and a prime (P). The game is played in rounds, and in every round the following steps occur:
1. Alice provides a sequence (T = [T_0, T_1, \dots, T_{N-1}]) of positive integers.
2. Bob, after seeing (T), chooses an integer (x) from (0) to (N-1).
3. A new sequence (S') is obtained by updating each index (i) as follows:
[
S'i = S_i + T{(i+x) \bmod N}
]
4. The sequence (S') becomes the new (S).
Alice wins if at the end of any round every entry of (S) is a multiple of (P) (i.e. (S_i \equiv 0 \pmod{P}) for all (i)).
The question is: given the initial sequence (S) and the prime (P), does Alice have a strategy to force a win in a finite number of rounds regardless of Bob’s moves? If yes, what is the minimum number of rounds required to guarantee victory?
Note: The effect of Bob’s move is to cyclically shift the sequence (T) before it is added to (S). In other words, if Alice can cancel out the entries in (S) no matter how Bob chooses (x), then she can force a win.
inputFormat
The input consists of two lines. The first line contains two integers (N) and (P) (where (P) is a prime). The second line contains (N) space‐separated integers representing the initial sequence (S_0, S_1, \dots, S_{N-1}).
outputFormat
Output a single integer. If Alice can force a win in a finite number of rounds, output the minimum number of rounds required; otherwise, output -1.
sample
1 7
3
1