結果

問題 No.334 門松ゲーム
ユーザー FromBooskaFromBooska
提出日時 2023-04-12 12:40:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 76,288 KB
最終ジャッジ日時 2024-04-17 01:57:36
合計ジャッジ時間 2,071 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
51,712 KB
testcase_01 AC 44 ms
51,968 KB
testcase_02 AC 110 ms
76,288 KB
testcase_03 AC 43 ms
51,968 KB
testcase_04 AC 43 ms
51,968 KB
testcase_05 AC 43 ms
52,096 KB
testcase_06 AC 96 ms
76,032 KB
testcase_07 AC 103 ms
76,032 KB
testcase_08 AC 74 ms
68,480 KB
testcase_09 AC 82 ms
71,296 KB
testcase_10 AC 114 ms
76,160 KB
testcase_11 AC 82 ms
72,576 KB
testcase_12 AC 51 ms
59,264 KB
testcase_13 AC 48 ms
57,856 KB
testcase_14 AC 80 ms
70,656 KB
testcase_15 AC 69 ms
67,200 KB
権限があれば一括ダウンロードができます

ソースコード

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