結果

問題 No.334 門松ゲーム
ユーザー rpy3cpp
提出日時 2016-01-16 00:03:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-09-19 19:37:28
合計ジャッジ時間 1,357 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

def read_data():
    N = int(input())
    Ks = list(map(int, input().split()))
    return N, Ks

def solve(N, Ks):
    if N < 3:
        return (-1, )
    for trio in itertools.combinations(range(N), 3):
        if not is_kado(trio, Ks):
            continue
        nKs = [k for i, k in enumerate(Ks) if i not in trio]
        result = solve(N - 3, nKs)
        if result == (-1, ):
            return trio
    return (-1, )

def is_kado(trio, Ks):
    a, b, c = [Ks[i] for i in trio]
    if a == b or b == c or a == c:
        return False
    return max(a, b, c) == b or min(a, b, c) == b
        

N, Ks = read_data()
print(*solve(N, Ks))
0