結果
問題 | No.334 門松ゲーム |
ユーザー |
![]() |
提出日時 | 2024-07-16 23:48:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 353 ms / 2,000 ms |
コード長 | 825 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 81,796 KB |
実行使用メモリ | 76,312 KB |
最終ジャッジ日時 | 2024-07-16 23:48:05 |
合計ジャッジ時間 | 3,283 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
from itertools import combinations def is_kadomatu(a: int, b: int, c: int) -> bool: if a == b or b == c or c == a: return False if a < b < c: return False if a > b > c: return False return True # ゲームに勝つか。先手(turn=1) def f(turn, used) -> bool: res = False for a, b, c in combinations(range(N), 3): if used[a] or used[b] or used[c]: continue if not is_kadomatu(A[a], A[b], A[c]): continue used[a] = used[b] = used[c] = turn res |= not f(turn+1, used) if res and turn == 1: return True used[a] = used[b] = used[c] = 0 return res N = int(input()) A = list(map(int, input().split())) used = [0] * N iswin = f(1, used) if not iswin: print(-1) exit() ans = [i for i in range(N) if used[i] == 1] print(*ans)