結果
| 問題 | No.1369 交換門松列・竹 | 
| コンテスト | |
| ユーザー |  hir355 | 
| 提出日時 | 2021-01-29 21:43:20 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 886 bytes | 
| コンパイル時間 | 168 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 77,440 KB | 
| 最終ジャッジ日時 | 2024-06-27 07:56:25 | 
| 合計ジャッジ時間 | 3,232 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 17 WA * 16 | 
ソースコード
import sys
def is_kadomatsu(a, b, c):
    if a != b != c and a != c and (a < b > c or a > b < c):
        return True
    else:
        return False
input = sys.stdin.readline
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    d = [0] * (n - 2)
    for i in range(n - 2):
        if not is_kadomatsu(a[i], a[i + 1], a[i + 2]):
            d[i] = 1
    s = sum(d)
    for i in range(n - 1):
        l = max(0, i - 2)
        r = min(n - 2, i + 2)
        cnt = 0
        for j in range(l, r):
            cnt += d[j]
        if cnt != s:
            continue
        flg = True
        a[i], a[i + 1] = a[i + 1], a[i]
        for j in range(l, r):
            flg &= is_kadomatsu(a[j], a[j + 1], a[j + 2])
        a[i], a[i + 1] = a[i + 1], a[i]
        if flg:
            print('Yes')
            break
    else:
        print('No')
            
            
            
        