結果
| 問題 |
No.284 門松と魔法(2)
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:17:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 758 bytes |
| コンパイル時間 | 321 ms |
| コンパイル使用メモリ | 82,348 KB |
| 実行使用メモリ | 90,436 KB |
| 最終ジャッジ日時 | 2025-06-12 15:18:13 |
| 合計ジャッジ時間 | 3,654 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 WA * 15 |
ソースコード
n = int(input())
A = list(map(int, input().split()))
# Remove adjacent duplicates
B = []
for num in A:
if not B or num != B[-1]:
B.append(num)
m = len(B)
if m < 3:
print(0)
else:
inc = 1 # length of the longest zigzag ending with an increase
dec = 1 # length of the longest zigzag ending with a decrease
for i in range(1, m):
if B[i] > B[i-1]:
new_inc = dec + 1
new_dec = dec
elif B[i] < B[i-1]:
new_dec = inc + 1
new_inc = inc
else:
# This case is redundant since B has no duplicates
new_inc = inc
new_dec = dec
inc, dec = new_inc, new_dec
max_len = max(inc, dec)
print(max_len if max_len >= 3 else 0)
gew1fw