結果
問題 | No.334 門松ゲーム |
ユーザー |
![]() |
提出日時 | 2019-12-19 23:24:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 78 ms / 2,000 ms |
コード長 | 700 bytes |
コンパイル時間 | 609 ms |
コンパイル使用メモリ | 82,040 KB |
実行使用メモリ | 76,576 KB |
最終ジャッジ日時 | 2024-07-07 02:06:51 |
合計ジャッジ時間 | 2,029 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
from itertools import combinations N = int(input()) K = list(map(int, input().split())) dp = [False]*(1<<N) for S in range((1<<N)-1, -1, -1): idx = [] for i in range(N): if not (S>>i)&1: idx.append(i) 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 dp[S] |= not dp[S_] for a, b, c in combinations(range(N), 3): S = 0 S |= 1<<a S |= 1<<b S |= 1<<c if ((K[a]<K[b] and K[b]>K[c]) or (K[a]>K[b] and K[b]<K[c])) and not dp[S]: print(a, b, c) exit() print(-1)