結果

問題 No.334 門松ゲーム
ユーザー lloyzlloyz
提出日時 2023-02-25 22:00:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 77,824 KB
最終ジャッジ日時 2023-10-11 17:47:12
合計ジャッジ時間 3,458 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,216 KB
testcase_01 AC 72 ms
71,096 KB
testcase_02 AC 138 ms
77,372 KB
testcase_03 AC 72 ms
71,300 KB
testcase_04 AC 74 ms
71,292 KB
testcase_05 AC 98 ms
76,660 KB
testcase_06 AC 99 ms
76,312 KB
testcase_07 AC 110 ms
76,972 KB
testcase_08 AC 110 ms
77,076 KB
testcase_09 AC 141 ms
77,824 KB
testcase_10 AC 132 ms
77,164 KB
testcase_11 AC 134 ms
77,216 KB
testcase_12 AC 133 ms
77,228 KB
testcase_13 AC 144 ms
77,268 KB
testcase_14 AC 132 ms
77,248 KB
testcase_15 AC 132 ms
77,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

# 遷移先がある場合は1としている
DP = [0 for _ in range(1 << n)]
for bit in range(1 << n):
    if DP[bit]:
        continue
    for i in range(n):
        if (bit >> i) & 1:
            continue
        for j in range(i + 1, n):
            if (bit >> j) & 1:
                continue
            for k in range(j + 1, n):
                if (bit >> k) & 1:
                    continue
                if A[i] != A[k] and (A[i] > A[j] < A[k] or A[i] < A[j] > A[k]):
                    nbit = bit
                    nbit |= (1 << i)
                    nbit |= (1 << j)
                    nbit |= (1 << k)
                    DP[nbit] = 1

for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if A[i] != A[k] and (A[i] > A[j] < A[k] or A[i] < A[j] > A[k]):
                bit = (1 << n) - 1
                bit ^= 1 << i
                bit ^= 1 << j
                bit ^= 1 << k
                if DP[bit] == 0:
                    print(i, j, k)
                    exit()
print(-1)
0