結果
| 問題 |
No.1369 交換門松列・竹
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:51:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,440 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 82,360 KB |
| 実行使用メモリ | 92,308 KB |
| 最終ジャッジ日時 | 2025-06-12 13:52:18 |
| 合計ジャッジ時間 | 6,480 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 15 TLE * 1 -- * 17 |
ソースコード
import sys
def is_kadomatsu(a, b, c):
if a == b or b == c or a == c:
return False
return (b > a and b > c) or (b < a and b < c)
def check_all(arr):
for i in range(len(arr)-2):
if not is_kadomatsu(arr[i], arr[i+1], arr[i+2]):
return False
return True
def solve():
input = sys.stdin.read().split()
idx = 0
T = int(input[idx])
idx +=1
for _ in range(T):
N = int(input[idx])
idx +=1
A = list(map(int, input[idx:idx+N]))
idx +=N
invalid = []
for i in range(N-2):
a, b, c = A[i], A[i+1], A[i+2]
if not is_kadomatsu(a, b, c):
invalid.append(i)
candidates = set()
for pos in invalid[:2]:
for j in range(max(0, pos-1), min(N, pos+3+1)):
candidates.add(j)
candidates = list(candidates)
found = False
for i in candidates:
for j in range(N):
if i == j:
continue
if A[i] == A[j]:
continue
A[i], A[j] = A[j], A[i]
if check_all(A):
found = True
A[i], A[j] = A[j], A[i]
if found:
break
if found:
break
print("Yes" if found else "No")
if __name__ == "__main__":
solve()
gew1fw