結果

問題 No.334 門松ゲーム
ユーザー gorugo30gorugo30
提出日時 2021-03-20 13:08:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 738 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 76,232 KB
最終ジャッジ日時 2024-04-30 23:28:20
合計ジャッジ時間 1,692 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,116 KB
testcase_01 AC 34 ms
52,568 KB
testcase_02 AC 62 ms
74,512 KB
testcase_03 AC 33 ms
53,052 KB
testcase_04 AC 35 ms
52,284 KB
testcase_05 AC 34 ms
53,488 KB
testcase_06 AC 55 ms
69,824 KB
testcase_07 AC 58 ms
70,440 KB
testcase_08 AC 49 ms
65,524 KB
testcase_09 AC 47 ms
64,124 KB
testcase_10 AC 70 ms
76,232 KB
testcase_11 AC 51 ms
67,040 KB
testcase_12 AC 40 ms
59,920 KB
testcase_13 AC 37 ms
58,916 KB
testcase_14 AC 56 ms
68,260 KB
testcase_15 AC 50 ms
66,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

from itertools import combinations

def solve(unused):
    l = []
    for i in range(N):
        if unused >> i & 1:
            l.append(i)
    if len(l) < 3:
        return [], False
    for C in combinations(l, 3):
        C = list(C)
        a, b, c = K[C[0]], K[C[1]], K[C[2]]
        if a == b or b == c or c == a:
            continue
        if not (b == max(a, b, c) or b == min(a, b, c)):
            continue
        unext = unused
        for i in range(3):
            unext &= ~(1 << C[i])
        ans, can = solve(unext)
        if can == False:
            return C, True
    return [], False

ans, can = solve((1 << N) - 1)
if can:
    print(*ans)
else:
    print(-1)
0