結果

問題 No.334 門松ゲーム
ユーザー roarisroaris
提出日時 2019-12-19 23:09:34
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 77,528 KB
最終ジャッジ日時 2023-09-21 07:38:04
合計ジャッジ時間 2,770 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,168 KB
testcase_01 AC 72 ms
71,372 KB
testcase_02 AC 113 ms
77,420 KB
testcase_03 AC 72 ms
71,352 KB
testcase_04 AC 74 ms
71,424 KB
testcase_05 AC 74 ms
71,192 KB
testcase_06 AC 88 ms
76,296 KB
testcase_07 AC 97 ms
76,632 KB
testcase_08 AC 96 ms
76,576 KB
testcase_09 AC 93 ms
76,428 KB
testcase_10 AC 113 ms
77,528 KB
testcase_11 AC 94 ms
76,736 KB
testcase_12 AC 116 ms
77,388 KB
testcase_13 AC 101 ms
76,504 KB
testcase_14 AC 92 ms
76,492 KB
testcase_15 AC 109 ms
77,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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