結果
問題 | No.334 門松ゲーム |
ユーザー |
![]() |
提出日時 | 2024-02-12 18:21:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,161 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 82,540 KB |
実行使用メモリ | 76,952 KB |
最終ジャッジ日時 | 2024-09-28 18:10:14 |
合計ジャッジ時間 | 1,919 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
# 自分のターンの選択によって次の相手のターンが全て負けに向かえば勝ち # 自分のターンの選択によって次の相手のターンが1つでも勝ちに向かえば負け # LISTの盤面で手番の人が勝つなら勝ち手、負けるなら-1 N = int(input()) K = list(map(int, input().split())) import sys sys.setrecursionlimit(10**7) def dfs(LIST): L = len(LIST) if L < 3: return -1 for a in range(L): for b in range(a+1, L): for c in range(b+1, L): temp = [LIST[a], LIST[b], LIST[c]] if len(set(temp)) != 3: continue if min(temp) != temp[1] and max(temp) != temp[1]: continue remaining = [] for i in range(L): if i != a and i != b and i != c: remaining.append(LIST[i]) if dfs(remaining) == -1: return [a, b, c] # 次の手番が負けるという場合がない=今の手番が負ける return -1 ans = dfs(K) if ans == -1: print(-1) else: print(*ans)