結果

問題 No.334 門松ゲーム
ユーザー FromBooskaFromBooska
提出日時 2023-04-12 12:37:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 52,096 KB
最終ジャッジ日時 2024-04-17 01:55:58
合計ジャッジ時間 1,327 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 30 ms
51,840 KB
testcase_02 WA -
testcase_03 AC 31 ms
51,456 KB
testcase_04 AC 32 ms
51,840 KB
testcase_05 AC 31 ms
51,840 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 33 ms
51,840 KB
testcase_13 AC 30 ms
51,456 KB
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# このdfsの実装は難しい

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

def dfs(LIST):
    # LISTの盤面で手番の人が勝つなら勝つ手、負けるなら0を返す
    L = len(LIST)
    
    for a in range(L):
        for b in range(a+1, L):
            for c in range(b+1, L):
                hand = [LIST[a], LIST[b], LIST[c]]
                if len(set(hand)) < 3:
                    # 同じ数があれば門松列にならない
                    # ここでreturn 0はダメだ、abcの取り方が悪いだけがある
                    continue
                if max(hand) == hand[1] or min(hand) == hand[1]:
                    new_LIST = []
                    for l in range(L):
                        if l != a and l != b and l != c:
                            new_LIST.append(LIST[l])
                        if dfs(new_LIST) == 0:
                            return (a, b, c)
    # 次の手番が負けるという場合がない=今の手番が負ける
    # 次の手番が負ける場合があればここに来ない
    # ここまで来るということは1回も勝ち手にならなかった=負け
    return 0
                
result = dfs(K)
if result == 0:
    print(-1)
else:
    print(*result)
0