結果

問題 No.2926 Botaoshi
ユーザー Yakumo221
提出日時 2024-10-12 15:15:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 710 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,544 KB
最終ジャッジ日時 2024-10-12 15:15:33
合計ジャッジ時間 5,290 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()

MOD = 998244353

# dp = [0,0,0]
#      [L,R,U]
if s[0] == ".":
    dp = [1,1,1]
elif s[0] == "L":
    dp = [1,0,0]
elif s[0] == "R":
    dp = [0,1,0]
else:
    dp = [0,0,1]

for i in range(1, n):
    c = s[i]
    ndp = [0,0,0]

    if c == "L":
        ndp[0] += dp[0]
        ndp[0] += dp[2]
        ndp[0] %= MOD
    elif c == "R":
        ndp[1] += sum(dp)
        ndp[1] %= MOD
    elif c == "U":
        ndp[2] += sum(dp)
        ndp[2] %= MOD
    
    else:
        ndp[0] += dp[0]
        ndp[0] += dp[2]
        ndp[0] %= MOD
        ndp[1] += sum(dp)
        ndp[1] %= MOD
        ndp[2] += sum(dp)
        ndp[2] %= MOD
    
    dp = ndp

ans = sum(dp) % MOD

print(ans)
0