結果
| 問題 | No.3753 Certainly a Cretan |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-19 00:54:00 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 1,889 bytes |
| 記録 | |
| コンパイル時間 | 1,089 ms |
| コンパイル使用メモリ | 218,000 KB |
| 実行使用メモリ | 20,120 KB |
| 最終ジャッジ日時 | 2026-10-02 20:57:09 |
| 合計ジャッジ時間 | 11,427 ms |
|
ジャッジサーバーID (参考情報) |
judge4_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 TLE * 1 -- * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
ll modpow(ll a, ll n) {
ll r = 1;
while (n) {
if (n & 1) r = r * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return r;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
cin >> N >> Q;
string S;
cin >> S;
vector<ll> fact(N + 1), invfact(N + 1);
fact[0] = 1;
for (int i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = modpow(fact[N], MOD - 2);
for (int i = N; i >= 1; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
auto C = [&](int n, int k) -> ll {
if (k < 0 || k > n) return 0;
return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
};
auto cat = [&](int r) -> ll {
return fact[2 * r] * invfact[r] % MOD * invfact[r + 1] % MOD;
};
auto solve = [&](int K) -> ll {
ll P = 1;
int last = 0;
int B = 0;
for (int i = 1; i < N; ++i) {
if (S[i - 1] == S[i]) continue;
if (i & 1) {
return 0;
}
P = P * cat((i - last) / 2) % MOD;
last = i;
B = i;
}
int L = N - B;
int q = K - B / 2;
if (S[N - 1] == 'Y') {
if (!(0 <= q && q <= L / 2)) return 0;
ll f = (C(L, q) - C(L, q - 1) + MOD) % MOD;
return P * f % MOD;
} else {
if (!((L + 1) / 2 <= q && q <= L)) return 0;
ll f = (C(L, q) - C(L, q + 1) + MOD) % MOD;
return P * f % MOD;
}
};
while (Q--) {
int t, x;
cin >> t >> x;
if (t == 1) {
--x;
S[x] = (S[x] == 'Y' ? 'N' : 'Y');
} else {
cout << solve(x) << '\n';
}
}
}