ALGO ARTIS プログラミングコンテスト2023 秋 (AtCoder Regular Contest 168)
B
Arbitrary Nim
AtCoder
⌀ 1289
原题
← AC →
翻译中…

Problem Statement

翻译中…

There are $N$ piles of stones, and the $i$-th pile ($1 \leq i \leq N$) has $A_i$ stones.

翻译中…

You will choose a positive integer $k$. Then, Alice and Bob will play a game with these piles as follows.

翻译中…
  • Starting with Alice, the players take turns to play.
  • In each turn, the player must choose a non-empty pile and remove from it some number of stones between $1$ and $k$, inclusive.
翻译中…

The person who cannot make a move on their turn loses, and the other person wins.

翻译中…

You want to choose a positive integer $k$ for which there is a winning strategy for Alice. Determine if such a $k$ exists. If it exists, determine if there is a maximum value for such $k$. If the maximum value exists, provide that value.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 250000$
  • $1 \leq A_i \leq 10^9$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \cdots A_N

翻译中…

Output

翻译中…

If there is no $k$ for which Alice has a winning strategy, print $0$.

翻译中…

If there is a $k$ for which Alice has a winning strategy, and there is no maximum value for such $k$, print $-1$.

翻译中…

If there is a $k$ for which Alice has a winning strategy, and there is a maximum value for such $k$, print that value.

翻译中…

样例

Input #1
3
1 2 3
Output #1
2
For example, if $k=2$, Alice has a winning strategy. If $k \geq 3$, Alice has no winning strategy, so the answer is $k=2$.
Input #2
4
1 2 3 4
Output #2
-1
For example, Alice has winning strategies for all $k=100,200,300,\cdots$. Thus, there is no maximum value for $k$, so print $-1$.
Input #3
2
100 100
Output #3
0
No matter what $k$ is chosen, Alice has no winning strategy. Thus, print $0$.
题目信息
题号
arc168_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。