結果

問題 No.2926 Botaoshi
ユーザー cologne
提出日時 2025-04-28 13:25:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 82,112 KB
実行使用メモリ 76,380 KB
最終ジャッジ日時 2025-04-28 13:26:05
合計ジャッジ時間 5,601 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    MOD = 998244353

    n = int(input())
    a = input()

    if a[0] == ".":
        dp = [1, 1, 1]
    elif a[0] == "L":
        dp = [1, 0, 0]
    elif a[0] == "U":
        dp = [0, 1, 0]
    elif a[0] == "R":
        dp = [0, 0, 1]

    for i in range(1, n):
        dp = [dp[0] + dp[1], dp[0] + dp[1] + dp[2], dp[0] + dp[1] + dp[2]]
        if a[i] == "L":
            dp[1] = dp[2] = 0
        if a[i] == "U":
            dp[0] = dp[2] = 0
        if a[i] == "R":
            dp[0] = dp[1] = 0
        dp = [x % MOD for x in dp]

    print(sum(dp) % MOD)


if __name__ == "__main__":
    main()
0