結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-01-29 21:58:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 648 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 114,764 KB
最終ジャッジ日時 2023-09-09 15:21:29
合計ジャッジ時間 7,784 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,472 KB
testcase_01 AC 71 ms
71,324 KB
testcase_02 WA -
testcase_03 AC 196 ms
78,524 KB
testcase_04 WA -
testcase_05 AC 441 ms
114,072 KB
testcase_06 AC 452 ms
114,408 KB
testcase_07 AC 328 ms
114,164 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0