結果

問題 No.2926 Botaoshi
ユーザー startcpp
提出日時 2024-10-12 15:51:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 94,212 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-10-12 15:52:01
合計ジャッジ時間 2,350 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <atcoder/modint>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
using namespace atcoder;
using mint = modint998244353;

int n;
string s;
mint dp[200001][3]; //L, R, U

signed main() {
    int i, j, k;

    cin >> n >> s;
    vector<int> a(n);
    rep(i, n) {
        if (s[i] == '.') a[i] = -1;
        if (s[i] == 'L') a[i] = 0;
        if (s[i] == 'R') a[i] = 1;
        if (s[i] == 'U') a[i] = 2;
    }

    dp[0][2] = 1;

    rep(i, n) {
        rep(j, 3) {
            rep(k, 3) {
                if (a[i] != -1 && k != a[i]) continue;
                if (j == 1 && k == 0) continue;
                dp[i + 1][k] += dp[i][j];
            }
        }
    }

    /*rep(i, n + 1) {
        rep(j, 3) {
            cout << dp[i][j].val() << " ";
        }
        cout << endl;
    }*/

    mint ans = 0;
    rep(i, 3) ans += dp[n][i];
    
    cout << ans.val() << endl;
    return 0;
}
0