結果

問題 No.2926 Botaoshi
ユーザー Nichi10p
提出日時 2024-10-12 16:58:57
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 834 bytes
コンパイル時間 3,004 ms
コンパイル使用メモリ 248,084 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-12 16:59:35
合計ジャッジ時間 4,445 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, t) for (auto i{s}; std::cmp_less(i, t); ++i)

#include <atcoder/modint>
typedef atcoder::modint998244353 Int;
ostream& operator<<(ostream &o, Int const &x) { return o << x.val(); }

struct DP { Int L, U, R; };

int main() {
  int N;
  string S;
  cin >> N >> S;

  vector<DP> dp(N);
  rep(i, 0, N) {
    if (i == 0) {
      dp[i].L = dp[i].U = dp[i].R = Int::raw(1);
    }
    else {
      dp[i].L = dp[i-1].L + dp[i-1].U;
      dp[i].U = dp[i-1].L + dp[i-1].U + dp[i-1].R;
      dp[i].R = dp[i-1].L + dp[i-1].U + dp[i-1].R;
    }
    if (S[i] == 'L')
      dp[i].U = dp[i].R = Int::raw(0);
    if (S[i] == 'U')
      dp[i].L = dp[i].R = Int::raw(0);
    if (S[i] == 'R')
      dp[i].L = dp[i].U = Int::raw(0);
  }

  cout << dp[N-1].L + dp[N-1].U + dp[N-1].R << endl;
}
0