結果

問題 No.2926 Botaoshi
ユーザー srjywrdnprkt
提出日時 2024-10-15 00:22:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 868 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 207,996 KB
最終ジャッジ日時 2025-02-24 19:40:05
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;
using ll = long long;
using mint=modint998244353;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    map<char, int> mp;
    mp['R'] = 0;
    mp['L'] = 1;
    mp['U'] = 2;
    mp['.'] = 3;
    int N, c;
    string S;
    cin >> N >> S;
    vector dp(N+1, vector<mint>(3));
    if (S[0] != '.') dp[1][mp[S[0]]] += 1;
    else{
        for (int i=0; i<3; i++) dp[1][i] += 1;
    }

    for (int i=2; i<=N; i++){
        c = mp[S[i-1]];
        for (int j=0; j<3; j++){
            for (int k=0; k<3; k++){
                if (c != 3 && k != c) continue;
                if (j == 0 && k == 1) continue;
                dp[i][k] += dp[i-1][j];
            }
        }
    }

    cout << (dp[N][0]+dp[N][1]+dp[N][2]).val() << endl;

    return 0;
}
0