結果

問題 No.1707 Simple Range Reverse Problem
ユーザー koba-e964koba-e964
提出日時 2021-10-15 21:31:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 62,144 KB
最終ジャッジ日時 2023-10-17 20:03:48
合計ジャッジ時間 1,786 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,516 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 44 ms
59,632 KB
testcase_05 AC 44 ms
59,632 KB
testcase_06 AC 47 ms
62,016 KB
testcase_07 AC 47 ms
62,016 KB
testcase_08 AC 47 ms
62,144 KB
testcase_09 AC 45 ms
59,968 KB
testcase_10 AC 45 ms
62,016 KB
testcase_11 AC 44 ms
59,964 KB
testcase_12 AC 47 ms
62,016 KB
testcase_13 AC 46 ms
59,968 KB
testcase_14 AC 43 ms
59,632 KB
testcase_15 AC 44 ms
59,964 KB
testcase_16 AC 42 ms
59,632 KB
testcase_17 AC 44 ms
59,632 KB
testcase_18 AC 42 ms
59,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

t = int(readline())

def calc(a):
    n = len(a) // 2
    f = [0] * (n + 1)
    for v in a:
        f[v] += 1
    for i in range(1, n + 1):
        if f[i] != 2:
            return False
    if a[0] != 1 or a[2 * n - 1] != n:
        return False
    if n == 1:
        return True
    u = [0] * (n + 1)
    for i in range(2 * n - 1):
        if a[i] == a[i + 1]:
            return False
        c = a[i]
        d = a[i + 1]
        if c > d:
            c, d = d, c
        if c == 1 and d == n:
            u[0] += 1
        else:
            if c + 1 != d:
                return False
            u[c] += 1
    if u[0] != 1:
        return False
    for i in range(1, n):
        if u[i] != 2:
            return False
    return True

for _ in range(t):
    n = int(readline())
    a = list(map(int, readline().split()))
    print('Yes' if calc(a) else 'No')
0