結果

問題 No.1369 交換門松列・竹
ユーザー titiatitia
提出日時 2021-01-29 22:32:15
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 865 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 86,704 KB
実行使用メモリ 113,296 KB
最終ジャッジ日時 2023-09-09 16:03:46
合計ジャッジ時間 12,143 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
74,616 KB
testcase_01 AC 78 ms
74,640 KB
testcase_02 AC 79 ms
74,620 KB
testcase_03 AC 77 ms
74,616 KB
testcase_04 AC 77 ms
74,548 KB
testcase_05 AC 76 ms
74,508 KB
testcase_06 AC 75 ms
71,064 KB
testcase_07 AC 105 ms
76,136 KB
testcase_08 AC 80 ms
74,912 KB
testcase_09 AC 91 ms
76,236 KB
testcase_10 AC 92 ms
76,064 KB
testcase_11 AC 78 ms
74,796 KB
testcase_12 AC 77 ms
74,760 KB
testcase_13 AC 273 ms
79,508 KB
testcase_14 AC 310 ms
80,092 KB
testcase_15 AC 158 ms
82,740 KB
testcase_16 AC 238 ms
83,064 KB
testcase_17 AC 235 ms
82,592 KB
testcase_18 AC 233 ms
82,652 KB
testcase_19 AC 158 ms
82,460 KB
testcase_20 AC 719 ms
83,184 KB
testcase_21 AC 221 ms
82,908 KB
testcase_22 AC 675 ms
82,532 KB
testcase_23 AC 234 ms
83,408 KB
testcase_24 AC 862 ms
82,916 KB
testcase_25 AC 768 ms
78,552 KB
testcase_26 AC 722 ms
79,508 KB
testcase_27 AC 754 ms
79,540 KB
testcase_28 AC 645 ms
82,024 KB
testcase_29 AC 865 ms
82,076 KB
testcase_30 AC 116 ms
113,296 KB
testcase_31 AC 116 ms
113,088 KB
testcase_32 AC 189 ms
78,440 KB
testcase_33 AC 270 ms
82,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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