結果
問題 | No.2926 Botaoshi |
ユーザー |
![]() |
提出日時 | 2025-04-03 02:09:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 193 ms / 2,000 ms |
コード長 | 1,327 bytes |
コンパイル時間 | 420 ms |
コンパイル使用メモリ | 82,172 KB |
実行使用メモリ | 77,916 KB |
最終ジャッジ日時 | 2025-04-03 02:09:36 |
合計ジャッジ時間 | 7,722 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 42 |
ソースコード
from enum import IntEnum, auto from functools import cache class E(IntEnum): S = 0 # 開始 L = auto() # L U = auto() # U R = auto() # R def nexts(self): match self: case E.S:return [E.L, E.U, E.R] case E.L:return [E.L, E.U, E.R] case E.U:return [E.L, E.U, E.R] case E.R:return [E.U, E.R] 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: list, op, e, init: dict): dp = [e for _ in range(len(E))] for k, v in init.items(): dp[k] = v for x in xs: pp = [e for _ in range(len(E))] 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: match v: case '.': return True case 'L': return to == E.L case 'U': return to == E.U case 'R': return to == E.R assert False def op(to: E, to_v, fm: E, fm_v, v): return (to_v + fm_v) % MOD MOD = 998244353 N = int(input()) S = input() dp = state_dp(S, op, 0, {E.S: 1}) ans = sum(dp) % MOD print(ans)