結果
| 問題 |
No.2926 Botaoshi
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2024-10-12 18:41:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 404 ms / 2,000 ms |
| コード長 | 1,043 bytes |
| コンパイル時間 | 560 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 98,816 KB |
| 最終ジャッジ日時 | 2024-10-12 18:42:08 |
| 合計ジャッジ時間 | 11,706 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 42 |
ソースコード
from enum import IntEnum, auto
# ステート遷移
class E(IntEnum):
S = 0 # S
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
def states():
for fm in E:
for to in fm.nexts():
yield fm, to
def is_match(c: str, to) -> bool:
match c:
case '.': return True
case 'L': return to == E.L
case 'U': return to == E.U
case 'R': return to == E.R
assert False
MOD = 998244353
N = int(input())
S = input()
dp = [[0] * len(E) for _ in range(N+1)]
dp[0][E.S] = 1
for i, c in enumerate(S):
for fm, to in E.states():
if dp[i][fm] == 0: continue
if not is_match(c, to): continue
dp[i+1][to] += dp[i][fm]
dp[i+1][to] %= MOD
ans = sum(dp[N]) % MOD
print(ans)
norioc