結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
FromBooska
|
| 提出日時 | 2023-07-29 09:50:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 101 ms / 2,000 ms |
| コード長 | 903 bytes |
| コンパイル時間 | 362 ms |
| コンパイル使用メモリ | 81,884 KB |
| 実行使用メモリ | 76,544 KB |
| 最終ジャッジ日時 | 2024-10-07 13:56:21 |
| 合計ジャッジ時間 | 2,270 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
# 苦手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)
FromBooska