結果

問題 No.1369 交換門松列・竹
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-01-29 22:26:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 1,408 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 82,996 KB
最終ジャッジ日時 2023-09-09 15:55:45
合計ジャッジ時間 6,944 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,188 KB
testcase_01 AC 74 ms
74,872 KB
testcase_02 AC 75 ms
75,060 KB
testcase_03 AC 74 ms
74,848 KB
testcase_04 AC 77 ms
75,028 KB
testcase_05 AC 75 ms
75,096 KB
testcase_06 AC 76 ms
75,052 KB
testcase_07 AC 72 ms
71,384 KB
testcase_08 AC 73 ms
71,388 KB
testcase_09 AC 70 ms
71,328 KB
testcase_10 AC 71 ms
71,320 KB
testcase_11 AC 70 ms
71,348 KB
testcase_12 AC 72 ms
71,412 KB
testcase_13 AC 247 ms
79,956 KB
testcase_14 AC 395 ms
82,696 KB
testcase_15 AC 239 ms
82,692 KB
testcase_16 AC 100 ms
82,348 KB
testcase_17 AC 100 ms
82,428 KB
testcase_18 AC 100 ms
82,232 KB
testcase_19 AC 261 ms
82,892 KB
testcase_20 AC 99 ms
82,232 KB
testcase_21 AC 263 ms
82,996 KB
testcase_22 AC 99 ms
82,280 KB
testcase_23 AC 98 ms
82,160 KB
testcase_24 AC 101 ms
82,388 KB
testcase_25 AC 135 ms
77,780 KB
testcase_26 AC 165 ms
77,920 KB
testcase_27 AC 190 ms
78,804 KB
testcase_28 AC 98 ms
81,988 KB
testcase_29 AC 99 ms
81,820 KB
testcase_30 AC 85 ms
81,640 KB
testcase_31 AC 86 ms
81,592 KB
testcase_32 AC 235 ms
80,072 KB
testcase_33 AC 99 ms
82,000 KB
権限があれば一括ダウンロードができます

ソースコード

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 += 2
        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