結果
| 問題 |
No.2926 Botaoshi
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-12 16:33:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| コード長 | 6,981 bytes |
| コンパイル時間 | 2,351 ms |
| コンパイル使用メモリ | 203,140 KB |
| 最終ジャッジ日時 | 2025-02-24 18:36:19 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <typename T> using min_priority_queue = priority_queue<T,vector<T>,greater<T>>;
random_device seed_gen;
mt19937 engine(seed_gen());
int64_t get_time(){
struct::timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return t.tv_sec * int64_t(1'000'000'000) + t.tv_nsec;
}
template<typename T>
void invec(vector<T> &v){
for(auto &i : v) cin >> i;
return;
}
template<typename T>
void outvec(vector<T> &v, string s = " "){
bool b = false;
for(auto i : v){
if(b) cout << s;
else b = true;
cout << i;
}
cout << endl;
return;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b; // aをbで更新
return true;
}
return false;
}
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b; // aをbで更新
return true;
}
return false;
}
template<typename T>
T pow_mod(T a, T b, T n){
a %= n;
if(a == 0) return 0;
if(a == 1 || b == 0) return 1;
if(b == 1) return a;
T c = b/2;
T d = b%2;
T ac = pow_mod(a,c,n);
T ad = pow_mod(a,d,n);
return ac*ac%n*ad%n;
}
template <typename T>
T ex_euclid(T a, T b, T &x, T &y){
T d = a;
if(b != 0){
d = ex_euclid(b, a%b, y, x);
y -= (a/b)*x;
}
else{
x = 1;
y = 0;
}
//cout << a << " * " << x << " + " << b << " * " << y << " = " << d << endl;
return d;
}
template <int64_t mod>
struct modint{
int64_t val;
modint(){
val = 0;
}
modint(int64_t a){
if(a <= -mod) a %= mod;
else if(a >= mod) a %= mod;
if(a < 0) a += mod;
val = a;
}
modint inv(){
int64_t x, k;
int64_t d = ex_euclid(val, mod, x, k);
assert(d == 1);
return modint(x);
}
bool operator==(modint other){
return val == other.val;
}
bool operator!=(modint other){
return val != other.val;
}
modint operator+(modint other){
return modint(val + other.val);
}
modint operator-(modint other){
return modint(val - other.val);
}
modint operator*(modint other){
return modint(val * other.val);
}
modint operator/(modint other){
return modint(val * other.inv().val);
}
void operator+=(modint other){
val += other.val;
if(val >= mod) val -= mod;
}
void operator-=(modint other){
val -= other.val;
if(val < 0) val += mod;
}
void operator*=(modint other){
val *= other.val;
val %= mod;
}
void operator/=(modint other){
val *= other.inv().val;
val %= mod;
}
void operator++(){
val++;
if(val >= mod) val -= mod;
}
void operator--(){
val--;
if(val < 0) val += mod;
}
};
template <int64_t mod>
modint<mod> pow(modint<mod> a, int64_t b){
using mint = modint<mod>;
if(b <= -(mod - 1)) b %= mod - 1;
else if(b >= (mod - 1)) b %= mod - 1;
if(b < 0) b += mod - 1;
if(a == 0) return mint(0);
if(b == 0) return mint(1);
if(a == 1) return mint(1);
if(b == 1) return a;
mint x = pow(a, b / 2);
mint y = pow(a, b % 2);
return x * x * y;
}
template <int64_t mod>
pair<vector<modint<mod>>, vector<modint<mod>>> init_mod_factorial(int N){
using mint = modint<mod>;
vector<mint> v(N+1);
vector<mint> v_inv(N+1);
for(int i = 0; i <= N; i++){
if(i == 0) v[i] = 1;
else v[i] = v[i - 1] * i;
}
for(int i = N; i >= 0; i--){
if(i == N) v_inv[i] = v[i].inv();
else v_inv[i] = v_inv[i+1] * (i + 1);
}
return make_pair(v, v_inv);
}
template <int64_t mod>
modint<mod> factorial_mod(int64_t x, pair<vector<modint<mod>>, vector<modint<mod>>> &factorial_list){
return factorial_list.first[x];
}
template <int64_t mod>
modint<mod> factorial_inv_mod(int64_t x, pair<vector<modint<mod>>, vector<modint<mod>>> &factorial_list){
return factorial_list.second[x];
}
template <int64_t mod>
modint<mod> comb_mod(int64_t x, int64_t y, pair<vector<modint<mod>>, vector<modint<mod>>> &factorial_list){
if(y < 0 || x < y) return modint<mod>(0);
return factorial_list.first[x] * factorial_list.second[y] * factorial_list.second[x - y];
}
bool yn(bool b){
if(b) cout << "Yes" << endl;
else cout << "No" << endl;
return b;
}
bool check_with_simple_solution;
bool calc_time;
bool random_input;
bool debug_output;
int num_of_testcase;
using ans_type = int;
void input(){
if(num_of_testcase > 1){
}
if(random_input){
}
else{
}
return;
}
void output_input(){
return;
}
void pre_solve(){
return;
}
ans_type solve(){
const int64_t mod = 998244353;
using mint = modint<mod>;
int n; cin >> n;
string s; cin >> s;
vector DP(n+1, vector<mint>(3, 0));
DP[0][0] = 1;
for(int i = 0; i < n; i++) {
char c = s[i];
if(c == 'L' || c == '.') {
DP[i+1][0] += DP[i][0] + DP[i][1];
}
if(c == 'U' || c == '.') {
DP[i+1][1] += DP[i][0] + DP[i][1] + DP[i][2];
}
if(c == 'R' || c == '.') {
DP[i+1][2] += DP[i][0] + DP[i][1] + DP[i][2];
}
}
mint ans = DP[n][0] + DP[n][1] + DP[n][2];
cout << ans.val << endl;
return ans_type();
}
ans_type solve_simple(){
return ans_type();
}
void output(ans_type ans){
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
check_with_simple_solution = 0;
calc_time = 0;
random_input = 0;
debug_output = 0;
num_of_testcase = 1;
if(num_of_testcase == 0) cin >> num_of_testcase;
pre_solve();
if(check_with_simple_solution){
for(int i = 0; i < num_of_testcase; i++){
if(debug_output) cout << "begin case " << i << " " << string(16, '=') << endl;
input();
ans_type ans = solve();
if(debug_output) cout << string(16, '=') << endl;
ans_type ans_simple = solve_simple();
if(ans != ans_simple){
cout << "input: " << endl;
output_input();
cout << "output: " << endl;
output(ans);
cout << "expected: " << endl;
output(ans_simple);
}
if(debug_output) cout << "end case " << i << " " << string(16, '=') << endl;
}
}
else{
int64_t time_start = get_time();
for(int i = 0; i < num_of_testcase; i++){
input();
output(solve());
}
int64_t time_end = get_time();
if(calc_time){
double time_per_case = (time_end - time_start) / (1e9 * num_of_testcase);
cout << fixed << setprecision(3) << time_per_case << "[second/case]" << endl;
}
}
return 0;
}