結果

問題 No.1369 交換門松列・竹
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-01-29 22:21:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,421 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 82,592 KB
最終ジャッジ日時 2023-09-09 15:49:45
合計ジャッジ時間 5,802 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,980 KB
testcase_01 AC 89 ms
74,836 KB
testcase_02 WA -
testcase_03 AC 72 ms
70,788 KB
testcase_04 AC 73 ms
70,744 KB
testcase_05 AC 76 ms
74,836 KB
testcase_06 AC 78 ms
74,668 KB
testcase_07 AC 71 ms
71,032 KB
testcase_08 AC 74 ms
70,888 KB
testcase_09 AC 72 ms
70,920 KB
testcase_10 AC 71 ms
70,972 KB
testcase_11 WA -
testcase_12 AC 73 ms
70,944 KB
testcase_13 AC 361 ms
80,616 KB
testcase_14 WA -
testcase_15 AC 102 ms
81,760 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 100 ms
81,844 KB
testcase_20 AC 99 ms
81,820 KB
testcase_21 AC 99 ms
81,812 KB
testcase_22 AC 99 ms
82,116 KB
testcase_23 WA -
testcase_24 AC 100 ms
81,880 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 100 ms
81,864 KB
testcase_29 AC 100 ms
81,472 KB
testcase_30 AC 85 ms
81,964 KB
testcase_31 AC 84 ms
81,984 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

離散して3箇所以上ある場合は不可能

"""

from sys import stdin
import sys

def kd(L):
    if L[0]==L[1] or L[1]==L[2] or L[2]==L[0]:
        return False
    elif max(L) == L[1] or min(L) == L[1]:
        return True
    else:
        return False


def kdl(L):
    for i in range(len(L)-2):
        if not kd(L[i:i+3]):
            return False
    return True


TT = int(stdin.readline())

for loop in range(TT):


    N = int(stdin.readline())
    A = list(map(int,stdin.readline().split()))
    
    nonKD = []

    cnt = 0
    while cnt < N-2:
        if not kd( A[cnt:cnt+3] ):
            nonKD.append(cnt)
            cnt += 1
        cnt += 1

    if len(nonKD) >= 3:
        print ("No")
        continue

    if len(nonKD) == 2:
        ans = "No"
        l = nonKD[0]
        r = nonKD[1]
        for i in range(3):
            for j in range(3):
                A[l+i],A[r+j] = A[r+j],A[l+i]
                if kdl(A[max(0,l-2):l+5]) and kdl(A[max(0,r-2):r+5]):
                    ans = "Yes"
                A[l+i],A[r+j] = A[r+j],A[l+i]
        print (ans)

    else:
        ans = "No"
        l = nonKD[0]
        for i in range(3):
            for j in range(N):
                A[l+i],A[j] = A[j],A[l+i]
                if kdl(A[max(0,l-2):l+5]) and kdl(A[max(0,j-2):j+3]):
                    ans = "Yes"
                A[l+i],A[j] = A[j],A[l+i]
        print (ans)
            
0