結果

問題 No.1707 Simple Range Reverse Problem
ユーザー koba-e964koba-e964
提出日時 2021-10-15 21:45:12
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 61,824 KB
最終ジャッジ日時 2023-10-17 20:11:24
合計ジャッジ時間 1,793 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,480 KB
testcase_01 AC 45 ms
59,828 KB
testcase_02 AC 45 ms
59,768 KB
testcase_03 AC 44 ms
59,768 KB
testcase_04 AC 43 ms
59,768 KB
testcase_05 AC 43 ms
59,768 KB
testcase_06 AC 46 ms
59,768 KB
testcase_07 AC 45 ms
59,768 KB
testcase_08 AC 45 ms
59,872 KB
testcase_09 AC 43 ms
59,768 KB
testcase_10 AC 44 ms
59,768 KB
testcase_11 AC 43 ms
59,828 KB
testcase_12 AC 43 ms
59,836 KB
testcase_13 AC 44 ms
59,836 KB
testcase_14 AC 43 ms
59,836 KB
testcase_15 AC 44 ms
59,768 KB
testcase_16 AC 45 ms
59,768 KB
testcase_17 AC 43 ms
59,828 KB
testcase_18 AC 45 ms
61,824 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 = [[] for _ in range(n + 1)]
    for i in range(2 * n):
        f[a[i]].append(i)
    for i in range(1, n + 1):
        if len(f[i]) != 2:
            return False
    if a[0] != 1 or a[2 * n - 1] != n:
        return False
    if n == 1:
        return True
    if all(a[i] == i % n + 1 for i in range(2 * n)):
        return True
    x = f[1][1]
    if x == n and f[n][0] == 1:
        x = 0
    b = [0] * (2 * n)
    y = x // 2
    for i in range(y + 1):
        b[i] = i + 1
    for i in range(y):
        b[y + 1 + i] = y - i
    for i in range(n - y):
        b[2 * y + 1 + i] = n - i
    for i in range(n - y - 1):
        b[2 * y + 1 + n - y + i] = y + 2 + i
    return a == b

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