結果

問題 No.334 門松ゲーム
コンテスト
ユーザー FromBooska
提出日時 2023-07-29 09:50:13
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 62 ms / 2,000 ms
+ 372µs
コード長 903 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 75 ms
コンパイル使用メモリ 80,896 KB
実行使用メモリ 84,096 KB
最終ジャッジ日時 2026-09-11 14:21:33
合計ジャッジ時間 2,106 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 苦手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