結果

問題 No.1369 交換門松列・竹
ユーザー convexineqconvexineq
提出日時 2021-01-30 09:21:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 475 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 85,424 KB
最終ジャッジ日時 2023-09-10 05:33:08
合計ジャッジ時間 8,258 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,552 KB
testcase_01 AC 71 ms
71,432 KB
testcase_02 AC 74 ms
71,416 KB
testcase_03 AC 71 ms
71,112 KB
testcase_04 AC 69 ms
71,644 KB
testcase_05 AC 71 ms
71,252 KB
testcase_06 AC 71 ms
71,228 KB
testcase_07 AC 70 ms
71,352 KB
testcase_08 AC 69 ms
71,428 KB
testcase_09 AC 71 ms
71,564 KB
testcase_10 AC 70 ms
71,228 KB
testcase_11 AC 70 ms
71,336 KB
testcase_12 AC 72 ms
71,404 KB
testcase_13 AC 356 ms
82,556 KB
testcase_14 AC 475 ms
81,768 KB
testcase_15 AC 143 ms
83,848 KB
testcase_16 AC 156 ms
84,268 KB
testcase_17 AC 149 ms
84,412 KB
testcase_18 AC 146 ms
84,152 KB
testcase_19 AC 137 ms
84,548 KB
testcase_20 AC 150 ms
84,620 KB
testcase_21 AC 135 ms
84,500 KB
testcase_22 AC 158 ms
84,612 KB
testcase_23 AC 144 ms
84,268 KB
testcase_24 AC 91 ms
83,156 KB
testcase_25 AC 236 ms
79,560 KB
testcase_26 AC 210 ms
78,732 KB
testcase_27 AC 204 ms
78,252 KB
testcase_28 AC 89 ms
82,516 KB
testcase_29 AC 89 ms
82,548 KB
testcase_30 AC 89 ms
85,408 KB
testcase_31 AC 86 ms
85,424 KB
testcase_32 AC 241 ms
79,548 KB
testcase_33 AC 182 ms
84,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_kadomatsu(a,b,c):
    return a!=b and b!=c and c!=a and (b==max(a,b,c) or b==min(a,b,c))

def check(a,res):
    return all(is_kadomatsu(a[i],a[i+1],a[i+2]) for i in res)

def checkv(a,i):
    if i < n-2 and not is_kadomatsu(a[i],a[i+1],a[i+2]): return False
    if 0 <= i-1 < n-2 and not is_kadomatsu(a[i-1],a[i],a[i+1]): return False
    if 0 <= i-2 < n-2 and not is_kadomatsu(a[i-2],a[i-1],a[i]): return False
    return True

def solve(n,a):
    res = [i for i in range(n-2) if not is_kadomatsu(a[i],a[i+1],a[i+2])]
    if len(res) >= 7: return 0
    v = res[0]
    for i in range(v,min(v+3,n)):
        for j in range(n):
            if i==j: continue
            a[i],a[j] = a[j],a[i]
            if check(a,res) and checkv(a,i) and checkv(a,j):
                return 1
            a[i],a[j] = a[j],a[i]
    return 0    

T = int(input())
for _ in range(T):
    n = int(input())
    *a, = map(int,input().split())
    print("Yes" if solve(n,a) else "No")
0