結果

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

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
#input = sys.stdin.readline
n = int(input())
s = input().rstrip()
dp = [[0,0,0] for i in range(n)]
mod = 998244353
if s[0] == 'L':
    dp[0][0] = 1
elif s[0] == 'R':
    dp[0][1]= 1
elif s[0] == 'U':
    dp[0][2] = 1
else:
    dp[0][0] = 1
    dp[0][1] = 1
    dp[0][2] = 1
    
for i in range(1,n):
    for j in range(3):
        if j == 0:
            if s[i] == 'R'or s[i] == 'U':
                continue
        if j == 1:
            if s[i] == 'L'or s[i] == 'U':
                continue
        if j == 2:
            if s[i] == 'R'or s[i] == 'L':
                continue


        for k in range(3):
            if j == 0 and k == 1:
                continue
            dp[i][j] += dp[i-1][k]
            dp[i][j] %= mod
print(sum(dp[-1])%mod)
0