結果
問題 | No.334 門松ゲーム |
ユーザー |
|
提出日時 | 2019-12-19 23:09:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 740 bytes |
コンパイル時間 | 143 ms |
コンパイル使用メモリ | 82,920 KB |
実行使用メモリ | 76,668 KB |
最終ジャッジ日時 | 2024-07-07 02:01:58 |
合計ジャッジ時間 | 1,741 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
from itertools import combinations def dfs(S): if memo[S]!=-1: return memo[S] idx = [] for i in range(N): if not (S>>i)&1: idx.append(i) res = False for a, b, c in combinations(idx, 3): if (K[a]<K[b] and K[b]>K[c]) or (K[a]>K[b] and K[b]<K[c]): S_ = S S_ |= 1<<a S_ |= 1<<b S_ |= 1<<c res |= not dfs(S_) memo[S] = res return res N = int(input()) K = list(map(int, input().split())) memo = [-1]*(1<<N) dfs(0) for a, b, c in combinations(range(N), 3): S = 0 S |= 1<<a S |= 1<<b S |= 1<<c if memo[S]==False: print(a, b, c) exit() print(-1)