結果

問題 No.334 門松ゲーム
ユーザー FromBooskaFromBooska
提出日時 2023-03-10 14:22:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,517 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 76,040 KB
最終ジャッジ日時 2023-10-18 06:40:28
合計ジャッジ時間 2,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,328 KB
testcase_01 AC 38 ms
53,328 KB
testcase_02 AC 94 ms
75,900 KB
testcase_03 AC 37 ms
53,328 KB
testcase_04 AC 37 ms
53,328 KB
testcase_05 AC 37 ms
53,328 KB
testcase_06 AC 80 ms
75,628 KB
testcase_07 AC 79 ms
75,608 KB
testcase_08 AC 60 ms
68,156 KB
testcase_09 AC 63 ms
70,436 KB
testcase_10 AC 112 ms
76,040 KB
testcase_11 AC 68 ms
73,488 KB
testcase_12 AC 45 ms
59,524 KB
testcase_13 AC 41 ms
58,912 KB
testcase_14 AC 67 ms
72,496 KB
testcase_15 AC 63 ms
70,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# それぞれ独立な門松セットがKの中に何個あるか
# 独立な門松セットとは判定ができない、たとえば764354
# 745, 634に分ければ独立な2セットだが、先手が735を取れば勝ってしまう
# 独立アイディアは失敗
# スマートな方法ではなくDFSでゴリ押しするのか? たとえばABC025C
# ある盤面状態で手番の人は勝つのか負けるのか

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

def dfs(LIST):
    # LISTの盤面で手番の人が勝つなら勝つ手、負けるなら0
    #print('LIST', LIST)
    L = len(LIST)
    if L < 3:
        return 0
    for i in range(L):
        for j in range(i+1, L):
            for k in range(j+1, L):
                # ijkすべて選べなければここに達しない
                hand = [LIST[i], LIST[j], LIST[k]]
                if len(set(hand)) == 3:
                    if min(hand) == hand[1] or max(hand) == hand[1]:
                        new_LIST = []
                        for l in range(L):
                            if l != i and l != j and l != k:
                                new_LIST.append(LIST[l])
                        if dfs(new_LIST) == 0:
                            # つまり次の手番が負けるのか
                            return [i, j, k]
    # 次の手番が負けるという場合がない=今の手番が負ける、もここに来る
    return 0

result = dfs(K)
if result == 0:
    print(-1)
else:
    print(*result)
0