結果
| 問題 | 
                            No.334 門松ゲーム
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-03-20 13:08:08 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 87 ms / 2,000 ms | 
| コード長 | 738 bytes | 
| コンパイル時間 | 245 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 76,288 KB | 
| 最終ジャッジ日時 | 2024-11-20 22:03:28 | 
| 合計ジャッジ時間 | 1,862 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 13 | 
ソースコード
N = int(input())
K = list(map(int, input().split()))
from itertools import combinations
def solve(unused):
    l = []
    for i in range(N):
        if unused >> i & 1:
            l.append(i)
    if len(l) < 3:
        return [], False
    for C in combinations(l, 3):
        C = list(C)
        a, b, c = K[C[0]], K[C[1]], K[C[2]]
        if a == b or b == c or c == a:
            continue
        if not (b == max(a, b, c) or b == min(a, b, c)):
            continue
        unext = unused
        for i in range(3):
            unext &= ~(1 << C[i])
        ans, can = solve(unext)
        if can == False:
            return C, True
    return [], False
ans, can = solve((1 << N) - 1)
if can:
    print(*ans)
else:
    print(-1)