結果

問題 No.334 門松ゲーム
ユーザー 👑 rin204rin204
提出日時 2022-01-20 03:54:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 64,384 KB
最終ジャッジ日時 2024-05-02 20:10:25
合計ジャッジ時間 1,646 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,096 KB
testcase_01 AC 38 ms
52,352 KB
testcase_02 AC 55 ms
63,872 KB
testcase_03 AC 34 ms
51,840 KB
testcase_04 AC 34 ms
51,968 KB
testcase_05 AC 43 ms
60,416 KB
testcase_06 AC 48 ms
62,080 KB
testcase_07 AC 49 ms
62,080 KB
testcase_08 AC 50 ms
62,208 KB
testcase_09 AC 49 ms
63,360 KB
testcase_10 AC 61 ms
64,384 KB
testcase_11 AC 54 ms
62,848 KB
testcase_12 AC 55 ms
63,616 KB
testcase_13 AC 53 ms
63,360 KB
testcase_14 AC 49 ms
62,848 KB
testcase_15 AC 54 ms
63,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
K = list(map(int, input().split()))

def kado(a, b, c):
    if len({a, b, c}) != 3:
        return False
    return b in [max(a, b, c), min(a, b, c)]
    
lst = []
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if kado(K[i], K[j], K[k]):
                lst.append((1 << i) | (1 << j) | (1 << k))
                

g = [0] * (1 << n)
for bit in range(1 << n):
    mex = set()
    for l in lst:
        if bit | l == bit:
            mex.add(g[bit ^ l])
    i = 0
    while i in mex:
        i += 1
    g[bit] = i

if g[-1] == 0:
    print(-1)
else:
    for l in lst:
        if g[l ^ bit] == 0:
            ans = []
            for i in range(n):
                if l >> i & 1:
                    ans.append(i)
            print(*ans)
            break
0