結果

問題 No.334 門松ゲーム
ユーザー flippergo
提出日時 2024-10-30 08:32:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 76,908 KB
最終ジャッジ日時 2024-10-30 08:32:10
合計ジャッジ時間 2,327 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations
N = int(input())
A = list(map(int,input().split()))
B = list(range(N))
def dfs(i,v):
    global B
    for u in combinations(B,3):
        x = A[u[0]]
        y = A[u[1]]
        z = A[u[2]]
        if x!=y and y!=z and z!=x and (y==max(x,y,z) or y==min(x,y,z)):
            if len(B)-3<3:
                return i,u
            B.remove(u[0])
            B.remove(u[1])
            B.remove(u[2])
            i1,u1 = dfs(1-i,u)
            if i1==i:
                B += u
                B = sorted(B)
                return i,u
            B += u
            B = sorted(B)
        else:continue
    return 1-i,v
i,u = dfs(0,[])
if i==0:
    print(*u)
else:
    print(-1)
0