結果

問題 No.334 門松ゲーム
ユーザー FromBooskaFromBooska
提出日時 2023-05-26 15:13:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 77,748 KB
最終ジャッジ日時 2023-08-26 07:09:25
合計ジャッジ時間 3,032 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,376 KB
testcase_01 AC 62 ms
71,256 KB
testcase_02 AC 176 ms
77,748 KB
testcase_03 AC 63 ms
71,256 KB
testcase_04 AC 63 ms
71,192 KB
testcase_05 AC 61 ms
71,408 KB
testcase_06 AC 94 ms
77,296 KB
testcase_07 AC 98 ms
77,476 KB
testcase_08 AC 82 ms
76,440 KB
testcase_09 AC 86 ms
76,500 KB
testcase_10 AC 112 ms
77,552 KB
testcase_11 AC 92 ms
77,260 KB
testcase_12 AC 69 ms
75,728 KB
testcase_13 AC 65 ms
75,348 KB
testcase_14 AC 86 ms
76,492 KB
testcase_15 AC 81 ms
76,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# dfs
#門松列は3個の長さすべてが違う必要ある

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

import sys
sys.setrecursionlimit(10**7)

def dfs(LIST):
    #print('LIST', LIST)
    L = len(LIST)
    if L < 3:
        return -1
    for i in range(L):
        for j in range(i+1, L):
            for k in range(j+1, L):
                temp = [LIST[i], LIST[j], LIST[k]]
                if len(set(temp)) == 3: #門松列は3個の長さすべてが違う必要ある
                    if max(temp) == LIST[j] or min(temp) == LIST[j]:
                        new_LIST = []
                        for l in range(L):
                            if l not in [i, j, k]:
                                new_LIST.append(LIST[l])
                        if dfs(new_LIST) == -1:
                            return [i, j, k]
    return -1
                
ans = dfs(K)
if ans == -1:
    print(-1)
else:
    print(*ans)
0