結果
問題 |
No.1369 交換門松列・竹
|
ユーザー |
![]() |
提出日時 | 2021-01-29 22:26:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 317 ms / 2,000 ms |
コード長 | 1,408 bytes |
コンパイル時間 | 138 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 82,048 KB |
最終ジャッジ日時 | 2024-06-27 08:42:59 |
合計ジャッジ時間 | 4,336 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 33 |
ソースコード
""" 離散して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)