結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <atcoder/modint>

using namespace std;
using ll = long long;
using mint93 = atcoder::modint998244353;

int main(){
  int n;
  string s;
  cin >> n >> s;
  vector dp(n, vector<mint93>(3));
  if (s[0] == 'L'){
    dp[0][0] = 1;
  }
  else if (s[0] == 'R'){
    dp[0][1] = 1;
  }
  else if (s[0] == 'U'){
    dp[0][2] = 1;
  }
  else {
    dp[0] = {1, 1, 1};
  }
  for (int i = 1; i < n; i++){
    if (s[i] == 'L' || s[i] == '.'){
      dp[i][0] += dp[i - 1][0] + dp[i - 1][2];
    }
    if (s[i] == 'R' || s[i] == '.'){
      dp[i][1] += dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2];
    }
    if (s[i] == 'U' || s[i] == '.'){
      dp[i][2] += dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2];
    }
  }
  cout << (dp[n - 1][0] + dp[n - 1][1] + dp[n - 1][2]).val() << endl;
}
0