結果
| 問題 |
No.2926 Botaoshi
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-12 16:15:51 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,183 bytes |
| コンパイル時間 | 1,542 ms |
| コンパイル使用メモリ | 128,024 KB |
| 実行使用メモリ | 17,536 KB |
| 最終ジャッジ日時 | 2024-10-12 16:15:57 |
| 合計ジャッジ時間 | 3,301 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 WA * 12 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>
#include <set>
#include <map>
#include <cassert>
using namespace std;
const int mod = 998244353;
using VL = vector<long long>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
int main() {
int n;
string s;
cin >> n >> s;
if (s.find("LR") != string::npos) {
cout << 0 << endl;
return 0;
}
// [iまでみた][棒の状態 LRUの順]
VVL dp(n+1, VL(4, 0));
dp[0][2] = 1; // 初期は倒れていない
for (int i = 0; i < n; i++) {
if (s[i] == 'L') {
dp[i+1][0] = dp[i][0] + dp[i][2]; // 右はだめ
} else if (s[i] == 'R') {
dp[i+1][1] = dp[i][0] + dp[i][1] + dp[i][2];
} else if (s[i] == 'U') {
dp[i+1][2] = dp[i][0] + dp[i][1] + dp[i][2];
} else {
// dot
dp[i+1][0] = dp[i][0] + dp[i][2]; // 右はだめ
dp[i+1][1] = dp[i][0] + dp[i][1] + dp[i][2];
dp[i+1][2] = dp[i][0] + dp[i][1] + dp[i][2];
}
for (int j = 0; j < 3; j++) {
dp[i+1][j] %= mod;
}
}
long long ans = 0;
ans += dp.back()[0];
ans += dp.back()[1];
ans += dp.back()[2];
ans %= mod;
cout << ans << endl;
return 0;
}