結果

問題 No.2518 Adjacent Larger
ユーザー MasKoaTSMasKoaTS
提出日時 2023-10-27 12:36:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,556 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 117,028 KB
最終ジャッジ日時 2023-10-27 12:36:13
合計ジャッジ時間 6,322 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
85,672 KB
testcase_01 AC 184 ms
89,280 KB
testcase_02 AC 157 ms
89,324 KB
testcase_03 AC 183 ms
89,296 KB
testcase_04 AC 159 ms
89,352 KB
testcase_05 AC 158 ms
89,296 KB
testcase_06 AC 139 ms
88,644 KB
testcase_07 AC 136 ms
88,660 KB
testcase_08 AC 136 ms
88,660 KB
testcase_09 AC 135 ms
88,648 KB
testcase_10 AC 133 ms
88,656 KB
testcase_11 AC 123 ms
88,416 KB
testcase_12 AC 137 ms
88,408 KB
testcase_13 AC 127 ms
88,480 KB
testcase_14 AC 128 ms
88,416 KB
testcase_15 AC 119 ms
88,408 KB
testcase_16 AC 153 ms
116,948 KB
testcase_17 AC 136 ms
103,216 KB
testcase_18 AC 136 ms
103,224 KB
testcase_19 AC 134 ms
101,204 KB
testcase_20 AC 146 ms
107,868 KB
testcase_21 AC 154 ms
116,964 KB
testcase_22 AC 144 ms
116,968 KB
testcase_23 AC 159 ms
117,028 KB
testcase_24 AC 147 ms
116,848 KB
testcase_25 AC 151 ms
116,980 KB
testcase_26 AC 152 ms
116,976 KB
testcase_27 AC 144 ms
116,988 KB
testcase_28 AC 170 ms
116,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools as iter
import collections as coll
import heapq as hq
import bisect as bis
from decimal import Decimal as dec
from functools import cmp_to_key
import math
import sys
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
sys.setrecursionlimit(10 ** 6)
inp = sys.stdin.readline
input = lambda : inp()[:-1]
getN = lambda : int(inp())
getNs = lambda : map(int, inp().split())
getList = lambda :list(map(int, inp().split()))
getStrs = lambda n : [input() for _ in [0] * n]
getEdges = lambda n : [[x - 1 for x in getNs()] for _ in [0] * n]
def yexit(): print("Yes"); exit(0)
def nexit(): print("No"); exit(0)
pi = 3.141592653589793
mod = 1000000007
MOD = 998244353
INF = 4611686018427387903
dx = [1, 0, -1, 0];  dy = [0, 1, 0, -1]
#di = coll.defaultdict(int)
 
 
"""
Main Code
"""

def solve(n, a):
    if(2 not in a):
        return "No"
    id_start = a.index(2)
    dirs = [0] * n
    for i in range(n):
        j = (id_start + i) % n
        k = (j - 1) % n
        if(a[j] == 2):
            dirs[j], dirs[k] = 1, 0
        elif(a[j] == 1):
            dirs[j] = dirs[k]
        else:
            dirs[j], dirs[k] = 0, 1
    for i in range(n):
        j = (id_start + i) % n
        k = (j - 1) % n
        if(a[j] == 2 and (dirs[j], dirs[k]) != (1, 0)):
            return "No"
        if(a[j] == 1 and dirs[j] != dirs[k]):
            return "No"
        if(a[j] == 0 and (dirs[j], dirs[k]) != (0, 1)):
            return "No"
    return "Yes"

t = getN()
for _ in [0] * t:
    n = getN()
    a = getList()
    print(solve(n, a))
0