結果

問題 No.334 門松ゲーム
ユーザー rlangevinrlangevin
提出日時 2023-01-14 01:05:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,057 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 78,424 KB
最終ジャッジ日時 2023-08-26 06:01:59
合計ジャッジ時間 3,396 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,288 KB
testcase_01 AC 73 ms
71,352 KB
testcase_02 AC 148 ms
77,648 KB
testcase_03 AC 73 ms
71,396 KB
testcase_04 AC 75 ms
71,224 KB
testcase_05 AC 101 ms
76,768 KB
testcase_06 AC 113 ms
77,332 KB
testcase_07 AC 119 ms
77,356 KB
testcase_08 AC 123 ms
77,460 KB
testcase_09 AC 142 ms
77,952 KB
testcase_10 AC 145 ms
77,688 KB
testcase_11 AC 127 ms
77,688 KB
testcase_12 AC 131 ms
77,764 KB
testcase_13 AC 133 ms
77,664 KB
testcase_14 AC 148 ms
78,424 KB
testcase_15 AC 134 ms
77,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def check(a, b, c):
    for i in [-1, 1]:
        if a * i < b * i and b * i > c * i and a != c:
            return True
    return False

N = int(input())
N2 = 1 << N
K = list(map(int, input().split()))
dp = [0] * (N2)

for s in range(N2):
    if dp[s]:
        continue
    for a in range(N):
        if (s >> a) & 1:
            continue
        for b in range(a + 1, N):
            if (s >> b) & 1:
                continue
            for c in range(b + 1, N):
                if (s >> c) & 1:
                    continue
                if check(K[a], K[b], K[c]):
                    ns = s
                    ns |= 1 << a
                    ns |= 1 << b
                    ns |= 1 << c
                    dp[ns] = 1

for a in range(N):
    for b in range(a + 1, N):
        for c in range(b + 1, N):
            if check(K[a], K[b], K[c]):
                s = (N2 - 1) ^ (1 << a)
                s ^= 1 << b
                s ^= 1 << c
                if dp[s] == 0:
                    print(a, b, c)
                    exit()
print(-1)     
0