結果

問題 No.2926 Botaoshi
ユーザー t98slider
提出日時 2024-10-12 14:54:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 4,305 ms
コンパイル使用メモリ 254,992 KB
最終ジャッジ日時 2025-02-24 17:46:39
ジャッジサーバーID
(参考情報)
judge3 / judge
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vector dp(n + 1, vector<mint>(3));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(s[i] == 'U'){
                dp[i + 1][0] += dp[i][j];
            }else if(s[i] == 'R'){
                dp[i + 1][1] += dp[i][j];
            }else if(s[i] == 'L'){
                if(j == 1) continue;
                dp[i + 1][2] += dp[i][j];
            }else{
                for(int k = 0; k < 3; k++){
                    if(j == 1 && k == 2) continue;
                    dp[i + 1][k] += dp[i][j];
                }
            }
        }
    }
    cout << accumulate(dp[n].begin(), dp[n].end(), mint(0)).val() << '\n';
}
0