B - Fennec VS. Snuke 2 解説 by evima
Hints: https://atcoder.jp/contests/arc192/editorial/12197
Since there is no need to distinguish between the terms of \(A\) whose indices are contained in \(S\), it suffices to solve the following problem.
A positive integer \(N\) and a sequence \(A=(A_1,A_2,\dots,A_N)\) of positive integers of length \(N\) are given. Also, there is a variable \(X\) initialized to \(0\). Fennec and Snuke take turns (starting with Fennec) performing the following sequence of operations:
- Choose and perform one of the following:
- Choose an index \(i\) with \(1\leq A_i\), add \(A_i-1\) to \(X\), and set \(A_i\) to \(0\).
- Subtract \(1\) from \(X\). This option is available when \(1\leq X\).
- When all elements of \(A\) become \(0\), the game ends and the player who performed the last operation wins.
Fennec and Snuke both play optimally to win. Who will win?
If one player has a winning strategy for a certain value of \(X\), then the player also has a winning strategy when \(X\) is increased by \(2\), as follows:
- Follow the winning strategy for the case \(X\) is \(2\) less. Once \(X = 2\), when the opponent operates on \(X\), also operate on \(X\).
Therefore, we may assume that \(X\leq 1\) while preserving its parity, and the problem reduces further to the following. Let \(C_o\) be the number of odd terms among the entries of \(A\), and \(C_e\) be the number of even terms.
Non-negative integers \(C_o,C_e\) are given, with the guarantee that \(1\leq C_o+C_e\). Also, there is a variable \(X\) initialized to \(0\). Fennec and Snuke take turns (starting with Fennec) performing the following sequence of operations:
- Choose and perform one of the following:
- Subtract \(1\) from \(C_o\). This is available when \(1\leq C_o\).
- Subtract \(1\) from \(C_e\), and replace \(X\) with \(1-X\). This is available when \(1\leq C_e\).
- Set \(X\) to \(0\). This is available when \(X=1\).
- When \(C_o=C_e=0\), the game ends and the current player wins.
Fennec and Snuke both play optimally to win. Who will win?
We now break into cases.
Type 1: Both \(C_o\) and \(C_e\) are even
Snuke has a winning strategy. He can simply mimic exactly the same operation chosen by Fennec.
Type 2: \(C_o\) is odd and \(C_e\) is even
Fennec has a winning strategy. By operating on \(C_o\) at the start, the situation reduces to Type 1.
Type 3: \(C_o=C_e=1\)
Snuke has a winning strategy. Once Fennec makes a move, Snuke can immediately end the game on his turn.
Type 4: Both \(C_o\) and \(C_e\) are odd, with \(C_e\ge 3\)
Fennec has a winning strategy. Begin by operating on \(C_o\). Then, proceed as follows:
- If Snuke operates on \(C_o\), Fennec does likewise.
- If Snuke operates on \(C_e\), Fennec operates on \(X\). After that, the game reduces to Type 1.
Type 5: Both \(C_o\) and \(C_e\) are odd, with \(C_o\ge 3\)
Fennec has a winning strategy. Begin by operating on \(C_e\). Then, proceed as follows:
- If Snuke operates on \(C_e\), Fennec does likewise.
- If Snuke operates on \(C_o\), Fennec operates on \(X\). After that, the game reduces to Type 1.
- If Snuke operates on \(X\), Fennec operates on \(C_o\). After that, the game reduces to Type 1.
Type 6: \(C_o=0\) and \(C_e=1\)
Fennec has a trivial winning strategy.
Type 7: \(C_o=2\) and \(C_e=1\)
Fennec has a winning strategy. By operating on \(C_o\) at the start, the situation reduces to Type 3.
Type 8: \(C_o\) is even and \(C_e\) is odd with \(C_e\ge 3\)
Snuke has a winning strategy. Proceed as follows:
- If Fennec operates on \(C_o\), then Snuke does the same.
- If Fennec operates on \(C_e\), then Snuke operates on \(X\). After that, the game reduces to Type 1.
Type 9: \(C_o\) is even and \(C_e\) is odd with \(C_o\ge 4\)
Snuke has a winning strategy. If Fennec operates on \(C_o\), then the game reduces to Type 5. If Fennec operates on \(C_e\), then afterwards Snuke can operate on \(X\) to reduce the situation to Type 1.
Thus, all cases have been covered. In summary, after some further organization, one can see that when \(N\ge 4\), the parity of \(C_o\) determines the outcome. Note that special care is needed when \(N\leq 3\).
N = int(input())
A = list(map(int, input().split()))
odd = 0
for a in A:
if a % 2 == 1:
odd += 1
if N == 1:
print("Fennec")
elif N == 2:
print("Snuke")
elif N == 3 and odd == 2:
print("Fennec")
elif odd % 2 == 1:
print("Fennec")
else:
print("Snuke")
投稿日時:
最終更新: