結果

問題 No.284 門松と魔法(2)
ユーザー gew1fw
提出日時 2025-06-12 15:18:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 647 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 92,032 KB
最終ジャッジ日時 2025-06-12 15:19:03
合計ジャッジ時間 3,680 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))

# Compress consecutive duplicates
compressed = []
prev = None
for num in A:
    if num != prev:
        compressed.append(num)
        prev = num
m = len(compressed)

if m < 3:
    print(0)
else:
    dp_inc = [1] * m
    dp_dec = [1] * m

    for i in range(1, m):
        if compressed[i] > compressed[i-1]:
            dp_inc[i] = dp_dec[i-1] + 1
            dp_dec[i] = dp_dec[i-1]
        elif compressed[i] < compressed[i-1]:
            dp_dec[i] = dp_inc[i-1] + 1
            dp_inc[i] = dp_inc[i-1]

    max_len = max(max(dp_inc), max(dp_dec))
    print(max_len if max_len >= 3 else 0)
0