結果
| 問題 | No.1368 サイクルの中に眠る門松列 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-01-29 21:58:06 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 648 bytes | 
| コンパイル時間 | 146 ms | 
| コンパイル使用メモリ | 82,132 KB | 
| 実行使用メモリ | 115,660 KB | 
| 最終ジャッジ日時 | 2024-06-27 08:11:35 | 
| 合計ジャッジ時間 | 6,988 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 5 WA * 10 | 
ソースコード
def is_kadomatsu(l):
    return len(set(l)) == 3 and (min(l) == l[1] or max(l) == l[1])
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split())) * 2
    l = [(a[i], i) for i in range(2 * n)]
    l.sort(key=lambda x:x[1])
    l.sort(key=lambda x:x[0], reverse=True)
    visited = [0] * n
    ans = 0
    for i in range(2 * n):
        v, ind = l[i]
        try:
            if all(not visited[(ind + j) % n] for j in range(3)) and is_kadomatsu(a[ind:ind + 3]):
                for j in range(3):
                    visited[(ind + j) % n] = 1
                ans += v
        except:
            pass
    print(ans)
            
            
            
        