結果

問題 No.334 門松ゲーム
ユーザー FromBooskaFromBooska
提出日時 2023-07-29 09:50:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 903 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 76,672 KB
最終ジャッジ日時 2024-04-16 16:29:58
合計ジャッジ時間 1,971 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
51,840 KB
testcase_01 AC 40 ms
51,968 KB
testcase_02 AC 88 ms
76,544 KB
testcase_03 AC 41 ms
51,840 KB
testcase_04 AC 38 ms
52,096 KB
testcase_05 AC 39 ms
52,352 KB
testcase_06 AC 74 ms
74,880 KB
testcase_07 AC 87 ms
76,416 KB
testcase_08 AC 61 ms
67,840 KB
testcase_09 AC 69 ms
71,552 KB
testcase_10 AC 99 ms
76,672 KB
testcase_11 AC 68 ms
72,960 KB
testcase_12 AC 46 ms
60,032 KB
testcase_13 AC 44 ms
57,600 KB
testcase_14 AC 68 ms
70,784 KB
testcase_15 AC 59 ms
67,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 苦手dfs練習
# N小さいので3個を全探索して、門松列になれば、残りを作りまたdfs

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

import sys
sys.setrecursionlimit(10**7)

def dfs(LIST):
    L = len(LIST)
    if L < 3:
        return -1
    
    for a in range(L):
        for b in range(a+1, L):
            for c in range(b+1, L):
                temp = [LIST[a], LIST[b], LIST[c]]
                if len(set(temp)) == 3:
                    if max(temp) == LIST[b] or min(temp) == LIST[b]:
                        remaining = []
                        for l in range(L):
                            if l != a and l != b and l != c:
                                remaining.append(LIST[l])
                        if dfs(remaining) == -1:
                            return [a, b, c]
    return -1
    
ans = dfs(K)
if ans == -1:
    print(-1)
else:
    print(*ans)
0