結果
| 問題 | 
                            No.921 ずんだアロー
                             | 
                    
| コンテスト | |
| ユーザー | 
                             norioc
                         | 
                    
| 提出日時 | 2025-10-11 06:24:34 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 258 ms / 2,000 ms | 
| コード長 | 1,627 bytes | 
| コンパイル時間 | 376 ms | 
| コンパイル使用メモリ | 82,436 KB | 
| 実行使用メモリ | 100,744 KB | 
| 最終ジャッジ日時 | 2025-10-11 06:24:42 | 
| 合計ジャッジ時間 | 8,032 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 22 | 
ソースコード
from collections.abc import Iterable
from enum import IntEnum, auto
from functools import cache
from unittest import case
class E(IntEnum):
    S = 0
    NONE = auto()
    APPLY = auto()
    def nexts(self):
        match self:
            case E.S: return [E.NONE, E.APPLY]
            case E.NONE: return [E.NONE, E.APPLY]
            case E.APPLY: return [E.APPLY, E.NONE]
        assert False
    @staticmethod
    @cache
    def states():
        res = []
        for fm in E:
            for to in fm.nexts():
                res.append((fm, to))
        return res
def state_dp(xs: Iterable, op, e, init: dict, *, is_reset=True):
    dp = [e] * len(E)
    for k, v in init.items():
        dp[k] = v
    for x in xs:
        pp = [e] * len(E) if is_reset else dp.copy()
        dp, pp = pp, dp
        for fm, to in E.states():
            if not is_valid(to, pp[fm], x): continue
            dp[to] = op(to, dp[to], fm, pp[fm], x)
    return dp
def is_valid(to: E, fm_v, v) -> bool:
    return True
def op(to: E, to_v, fm: E, fm_v, v):
    ma, size = fm_v
    match to:
        case E.NONE:
            return max(to_v, (ma, v))
        case E.APPLY:
            if fm == E.APPLY:
                if size == v:  # 同じ大きさなら消滅しない
                    return max(to_v, (ma+1, size))
                else:
                    return max(to_v, (ma, max(size, v)))
            else:
                return max(to_v, (ma+1, v))
    assert False
N = int(input())
A = list(map(int, input().split()))
dp = state_dp(A, op, (0, -1), {E.S: (0, -1)})
ans = max(ma for ma, _ in dp)
print(ans)
            
            
            
        
            
norioc