結果

問題 No.1707 Simple Range Reverse Problem
ユーザー shotoyooshotoyoo
提出日時 2021-10-15 23:44:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 905 bytes
コンパイル時間 1,137 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 66,280 KB
最終ジャッジ日時 2023-10-17 21:34:55
合計ジャッジ時間 2,936 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,416 KB
testcase_01 AC 48 ms
61,480 KB
testcase_02 AC 49 ms
61,480 KB
testcase_03 AC 49 ms
61,480 KB
testcase_04 AC 53 ms
64,192 KB
testcase_05 AC 53 ms
64,148 KB
testcase_06 AC 53 ms
64,216 KB
testcase_07 AC 53 ms
64,216 KB
testcase_08 AC 52 ms
64,148 KB
testcase_09 AC 53 ms
66,276 KB
testcase_10 AC 53 ms
66,276 KB
testcase_11 AC 52 ms
64,224 KB
testcase_12 AC 54 ms
66,280 KB
testcase_13 AC 55 ms
66,280 KB
testcase_14 AC 54 ms
64,232 KB
testcase_15 AC 53 ms
66,276 KB
testcase_16 AC 54 ms
66,276 KB
testcase_17 AC 51 ms
64,224 KB
testcase_18 AC 53 ms
66,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))
# sys.setrecursionlimit(3*10**5+10)
def sub(a):
    t = [[] for _ in range(n+1)]
    for i in range(2*n):
        v = a[i]
        l = []
        if i>0:
            l.append(a[i-1])
        if i+1<2*n:
            l.append(a[i+1])
        t[v].extend(l)
    for i in range(n+1):
        t[i] = tuple(sorted(t[i]))
    return t
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    if set(a)!=set(list(range(1,n+1))*2) or a[0]!=1 or a[-1]!=n:
        print("No")
        continue
    s1 = sub(a)
    s2 = sub(list(range(1,n+1)) + list(range(1,n+1)))
#     print(s1,s2)
    if all((s1[i]==s2[i] for i in range(n+1))):
        print("Yes")
    else:
        print("No")
0