結果

問題 No.334 門松ゲーム
ユーザー roarisroaris
提出日時 2019-12-19 23:24:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 77,636 KB
最終ジャッジ日時 2023-09-21 07:42:03
合計ジャッジ時間 2,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,280 KB
testcase_01 AC 74 ms
71,396 KB
testcase_02 AC 115 ms
77,312 KB
testcase_03 AC 74 ms
71,340 KB
testcase_04 AC 73 ms
71,264 KB
testcase_05 AC 91 ms
76,640 KB
testcase_06 AC 101 ms
76,804 KB
testcase_07 AC 106 ms
77,260 KB
testcase_08 AC 107 ms
77,152 KB
testcase_09 AC 114 ms
77,372 KB
testcase_10 AC 115 ms
77,176 KB
testcase_11 AC 116 ms
77,636 KB
testcase_12 AC 115 ms
77,436 KB
testcase_13 AC 111 ms
77,116 KB
testcase_14 AC 110 ms
77,400 KB
testcase_15 AC 109 ms
77,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0