結果

問題 No.1369 交換門松列・竹
ユーザー hir355hir355
提出日時 2021-01-29 21:43:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 886 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 82,440 KB
最終ジャッジ日時 2023-09-09 15:04:36
合計ジャッジ時間 4,994 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,184 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 68 ms
71,112 KB
testcase_04 AC 68 ms
70,960 KB
testcase_05 AC 67 ms
71,432 KB
testcase_06 WA -
testcase_07 AC 66 ms
70,960 KB
testcase_08 WA -
testcase_09 AC 69 ms
71,184 KB
testcase_10 AC 67 ms
71,328 KB
testcase_11 WA -
testcase_12 AC 67 ms
70,960 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 84 ms
82,172 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 85 ms
82,116 KB
testcase_20 AC 90 ms
82,176 KB
testcase_21 AC 85 ms
81,872 KB
testcase_22 AC 91 ms
82,052 KB
testcase_23 WA -
testcase_24 AC 88 ms
82,304 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 90 ms
81,936 KB
testcase_29 AC 88 ms
81,824 KB
testcase_30 AC 81 ms
82,124 KB
testcase_31 AC 84 ms
81,844 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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')
0