結果
| 問題 | No.1369 交換門松列・竹 | 
| コンテスト | |
| ユーザー | 👑  SPD_9X2 | 
| 提出日時 | 2021-01-29 22:21:57 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,421 bytes | 
| コンパイル時間 | 176 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 81,408 KB | 
| 最終ジャッジ日時 | 2024-06-27 08:37:33 | 
| 合計ジャッジ時間 | 3,767 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 21 WA * 12 | 
ソースコード
"""
離散して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)
            
            
            
            
        