結果

問題 No.1369 交換門松列・竹
ユーザー titiatitia
提出日時 2021-08-13 21:05:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 902 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 108,268 KB
最終ジャッジ日時 2024-04-14 15:58:16
合計ジャッジ時間 10,920 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
58,588 KB
testcase_01 AC 43 ms
60,000 KB
testcase_02 AC 43 ms
58,376 KB
testcase_03 AC 42 ms
58,648 KB
testcase_04 AC 40 ms
59,120 KB
testcase_05 AC 42 ms
57,644 KB
testcase_06 AC 38 ms
52,968 KB
testcase_07 AC 53 ms
66,356 KB
testcase_08 AC 42 ms
59,260 KB
testcase_09 AC 55 ms
67,068 KB
testcase_10 AC 58 ms
68,988 KB
testcase_11 AC 42 ms
59,032 KB
testcase_12 AC 41 ms
58,688 KB
testcase_13 AC 167 ms
77,276 KB
testcase_14 AC 199 ms
77,504 KB
testcase_15 AC 130 ms
82,964 KB
testcase_16 AC 205 ms
83,140 KB
testcase_17 AC 203 ms
83,260 KB
testcase_18 AC 230 ms
82,944 KB
testcase_19 AC 128 ms
82,412 KB
testcase_20 AC 682 ms
83,308 KB
testcase_21 AC 184 ms
82,996 KB
testcase_22 AC 638 ms
82,488 KB
testcase_23 AC 199 ms
82,824 KB
testcase_24 AC 872 ms
83,196 KB
testcase_25 AC 769 ms
77,692 KB
testcase_26 AC 698 ms
78,108 KB
testcase_27 AC 726 ms
79,012 KB
testcase_28 AC 660 ms
81,452 KB
testcase_29 AC 902 ms
81,796 KB
testcase_30 AC 83 ms
107,180 KB
testcase_31 AC 82 ms
108,268 KB
testcase_32 AC 130 ms
76,884 KB
testcase_33 AC 228 ms
82,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def kado(x,y,z):
    if x==z:
        return 0
    
    if y<x and y<z:
        return 1
    if y>x and y>z:
        return 1
    return 0
        
T=int(input())
for tests in range(T):
    N=int(input())
    A=list(map(int,input().split()))

    NO=[]
    for i in range(1,N-1):
        if kado(A[i-1],A[i],A[i+1])==0:
            NO.extend([i-3,i-2,i-1,i,i+1,i+2,i+3])

    NO=sorted(set(NO))

    flag=0

    if len(NO)<=500:
        for x in NO:
            if flag==1:
                break
            if x<0 or x>=N:
                continue
            for i in range(N):
                if flag==1:
                    break
                if x==i:
                    continue

                A[x],A[i]=A[i],A[x]

                for a in NO+list(range(x-5,x+6))+list(range(i-5,i+6)):
                    if a<=0 or a>=N-1:
                        continue
                    if kado(A[a-1],A[a],A[a+1])==0:
                        break
                else:
                    print("Yes")
                    flag=1
                    break

                A[x],A[i]=A[i],A[x]

    if flag==0:
        print("No")
                    
0