結果

問題 No.2518 Adjacent Larger
ユーザー ShirotsumeShirotsume
提出日時 2023-09-15 01:02:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,011 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 81,852 KB
実行使用メモリ 107,272 KB
最終ジャッジ日時 2023-10-25 16:29:47
合計ジャッジ時間 4,228 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
56,276 KB
testcase_01 AC 136 ms
77,808 KB
testcase_02 AC 136 ms
77,796 KB
testcase_03 AC 133 ms
77,908 KB
testcase_04 AC 130 ms
77,800 KB
testcase_05 AC 130 ms
77,784 KB
testcase_06 AC 98 ms
77,256 KB
testcase_07 AC 98 ms
77,188 KB
testcase_08 AC 102 ms
77,180 KB
testcase_09 AC 98 ms
77,256 KB
testcase_10 AC 98 ms
77,260 KB
testcase_11 AC 76 ms
76,800 KB
testcase_12 AC 79 ms
76,788 KB
testcase_13 AC 76 ms
76,812 KB
testcase_14 AC 80 ms
76,840 KB
testcase_15 AC 81 ms
76,848 KB
testcase_16 AC 120 ms
107,040 KB
testcase_17 AC 97 ms
93,928 KB
testcase_18 AC 97 ms
94,140 KB
testcase_19 AC 92 ms
90,240 KB
testcase_20 AC 107 ms
100,144 KB
testcase_21 AC 109 ms
107,068 KB
testcase_22 AC 110 ms
107,068 KB
testcase_23 AC 121 ms
107,068 KB
testcase_24 AC 101 ms
107,272 KB
testcase_25 AC 102 ms
107,064 KB
testcase_26 AC 111 ms
107,068 KB
testcase_27 AC 102 ms
107,064 KB
testcase_28 AC 108 ms
107,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
def check(n, a):
    d = deque(range(n))

    if 2 not in a:
        return False
    now = a.index(2)
    b = [0] * n
    f = 1
    for i in range(n):
        if a[(now + i) % n] == 0:
            b[(now + i) % n] = d.pop()
            f = 1
        elif a[(now + i) % n] == 2:
            b[(now + i) % n] = d.popleft()
            f = 0
        else:
            if f:
                b[(now + i) % n] = d.pop()
            else:
                b[(now + i) % n] = d.popleft()
    for i in range(n):
        if (b[(i - 1) % n] > b[i]) + (b[(i + 1) % n] > b[i]) == a[i]:
            pass
        else:
            return False
    return True

for _ in range(ii()):
    n = ii()
    a = li()
    if check(n, a):
        print('Yes')
    else:
        print('No')
0