結果

問題 No.1369 交換門松列・竹
ユーザー titiatitia
提出日時 2021-01-29 22:22:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,133 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 113,056 KB
最終ジャッジ日時 2023-09-09 15:50:08
合計ジャッジ時間 8,899 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,644 KB
testcase_01 WA -
testcase_02 AC 73 ms
74,496 KB
testcase_03 AC 74 ms
70,864 KB
testcase_04 AC 72 ms
70,752 KB
testcase_05 AC 72 ms
70,912 KB
testcase_06 AC 72 ms
70,900 KB
testcase_07 AC 85 ms
75,920 KB
testcase_08 AC 73 ms
71,000 KB
testcase_09 AC 87 ms
76,368 KB
testcase_10 AC 91 ms
75,952 KB
testcase_11 AC 75 ms
74,636 KB
testcase_12 AC 74 ms
71,016 KB
testcase_13 AC 257 ms
79,332 KB
testcase_14 AC 237 ms
78,992 KB
testcase_15 AC 140 ms
82,216 KB
testcase_16 AC 180 ms
82,452 KB
testcase_17 AC 185 ms
83,152 KB
testcase_18 AC 181 ms
82,588 KB
testcase_19 AC 139 ms
82,768 KB
testcase_20 AC 445 ms
83,500 KB
testcase_21 AC 174 ms
83,016 KB
testcase_22 AC 397 ms
82,660 KB
testcase_23 AC 172 ms
82,696 KB
testcase_24 AC 538 ms
82,852 KB
testcase_25 AC 508 ms
78,396 KB
testcase_26 AC 464 ms
78,752 KB
testcase_27 AC 485 ms
79,308 KB
testcase_28 AC 403 ms
82,108 KB
testcase_29 AC 541 ms
82,284 KB
testcase_30 AC 111 ms
113,008 KB
testcase_31 AC 109 ms
113,056 KB
testcase_32 AC 195 ms
78,016 KB
testcase_33 AC 202 ms
82,568 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(i-2,i+3)):
                    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