結果
問題 |
No.334 門松ゲーム
|
ユーザー |
![]() |
提出日時 | 2017-12-07 08:13:27 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 90 ms / 2,000 ms |
コード長 | 2,156 bytes |
コンパイル時間 | 114 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-11-29 04:05:26 |
合計ジャッジ時間 | 1,743 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
import copy N=int(input()) K=[int(i) for i in input().split()] ans=[] dp=[0 for i in range(2**N)] 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) state_index=0 for i in range(N): if state[i]==True: state_index+=2**i for nextState in nextStates: next_state_index=0 for i in range(N): if nextState[i]==True: next_state_index+=2**i if dp[next_state_index]==-1: if depth==0: # ans.append(copy.deepcopy(nextState)) ans=copy.deepcopy(nextState) # print(ans) dp[state_index]=1 return True elif dp[next_state_index]==1: continue elif not isWinning(nextState,depth+1): if depth==0: # ans.append(copy.deepcopy(nextState)) ans=copy.deepcopy(nextState) # print(ans) return True dp[state_index]=-1 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)