結果

問題 No.2518 Adjacent Larger
ユーザー StanMarshStanMarsh
提出日時 2023-10-28 01:53:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 917 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 81,488 KB
実行使用メモリ 105,796 KB
最終ジャッジ日時 2023-10-28 01:53:27
合計ジャッジ時間 4,533 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,940 KB
testcase_01 AC 136 ms
77,428 KB
testcase_02 AC 141 ms
77,424 KB
testcase_03 AC 143 ms
77,528 KB
testcase_04 AC 137 ms
77,384 KB
testcase_05 AC 134 ms
77,388 KB
testcase_06 AC 94 ms
76,724 KB
testcase_07 AC 94 ms
76,720 KB
testcase_08 AC 95 ms
76,800 KB
testcase_09 AC 96 ms
76,732 KB
testcase_10 AC 96 ms
76,712 KB
testcase_11 AC 78 ms
76,340 KB
testcase_12 AC 78 ms
76,360 KB
testcase_13 AC 77 ms
76,336 KB
testcase_14 AC 77 ms
76,356 KB
testcase_15 AC 76 ms
76,344 KB
testcase_16 AC 120 ms
105,452 KB
testcase_17 AC 88 ms
88,628 KB
testcase_18 AC 86 ms
88,388 KB
testcase_19 AC 82 ms
86,120 KB
testcase_20 AC 101 ms
96,060 KB
testcase_21 AC 104 ms
105,476 KB
testcase_22 AC 103 ms
105,476 KB
testcase_23 AC 118 ms
105,796 KB
testcase_24 AC 97 ms
102,172 KB
testcase_25 AC 99 ms
102,364 KB
testcase_26 AC 102 ms
102,756 KB
testcase_27 AC 100 ms
105,796 KB
testcase_28 AC 108 ms
105,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 抄的
# 思路:随便找一个 2 的位置,循环往后移动n,确定每个位置与其后面位置大小的相关性,然后和 a 进行检查
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 solve():
    n = ii()
    a = li()
    if 2 not in a:
        return 'No'
    p = a.index(2)
    
    d = [None] * n
    for i in range(p, p + n):
        i %= n
        to = None
        if a[i] == 2:
            to = '>'
        if a[i] == 0:
            to = '<'
        if a[i] == 1:
            to = d[(i - 1) % n]
        d[i] = to
    for i in range(n):
        if a[i] != (d[(i - 1) % n] == '<') + (d[i % n] == '>'):
            return 'No'
    return 'Yes'

for _ in range(ii()):
    print(solve())
    
0