結果

問題 No.334 門松ゲーム
ユーザー aka_satana_haaka_satana_ha
提出日時 2017-12-07 07:59:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,574 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 8,648 KB
最終ジャッジ日時 2023-08-19 11:25:14
合計ジャッジ時間 1,602 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,428 KB
testcase_01 AC 19 ms
8,552 KB
testcase_02 AC 88 ms
8,648 KB
testcase_03 AC 19 ms
8,580 KB
testcase_04 AC 19 ms
8,480 KB
testcase_05 AC 19 ms
8,484 KB
testcase_06 AC 41 ms
8,504 KB
testcase_07 AC 58 ms
8,528 KB
testcase_08 AC 32 ms
8,536 KB
testcase_09 AC 33 ms
8,440 KB
testcase_10 AC 141 ms
8,444 KB
testcase_11 AC 38 ms
8,572 KB
testcase_12 AC 25 ms
8,644 KB
testcase_13 AC 25 ms
8,520 KB
testcase_14 AC 38 ms
8,564 KB
testcase_15 AC 35 ms
8,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy

N=int(input())
K=[int(i) for i in input().split()]
ans=[]
def isWinning(state,depth):
    nextStates=[]
    now=state
    global ans
    #手の選択
    for i in range(N):
        if now[i]==False:
            continue
        for j in range(i+1,N):
            #a>b and b<c
            if K[i]>K[j] and now[j]==True:
                for m in range(j+1,N):
                    if K[j]<K[m] and now[m]==True:
                        nextK=copy.deepcopy(now)
                        nextK[i]=False
                        nextK[j]=False
                        nextK[m]=False
                        nextStates.append(nextK)
            #a<b and b>c
            if K[i]<K[j] and now[j]==True:
                for m in range(j+1,N):
                    if K[j]>K[m] and now[m]==True:
                        nextK=copy.deepcopy(now)
                        nextK[i]=False
                        nextK[j]=False
                        nextK[m]=False
                        nextStates.append(nextK)
    # print('now',now)
    # print('next',nextStates)
    for nextState in nextStates:
        if not isWinning(nextState,depth+1):
            if depth==0:
                # ans.append(copy.deepcopy(nextState))
                ans=copy.deepcopy(nextState)
                # print(ans)
            return True
    return False

start=[True for i in range(N)]
ret=isWinning(start,0)
# print(ret)
syote=[]
for i in range(len(ans)):
    if ans[i]==False:
        syote.append(i)
syote_string=' '.join(map(str,syote))
out=syote_string if ret==True else -1
print(out)
0