結果

問題 No.2926 Botaoshi
ユーザー amesyu
提出日時 2024-10-12 19:05:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 460 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2024-10-12 19:05:47
合計ジャッジ時間 5,331 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
n = int(input())
s = input()

dp = [0, 0, 0]
if s[0] == "L": dp[0] += 1
if s[0] == "R": dp[1] += 1
if s[0] == "U": dp[2] += 1
if s[0] == ".": dp = [1, 1, 1]

for i in range(1, n):
    ndp = [0, 0, 0]
    if s[i] == "L" or s[i] == ".":
        ndp[0] = (dp[0] + dp[2]) % MOD
    if s[i] == "R" or s[i] == ".":
        ndp[1] = sum(dp) % MOD
    if s[i] == "U" or s[i] == ".":
        ndp[2] = sum(dp) % MOD

    dp = ndp[::]
print(sum(dp)%MOD)

0