题解:CF2187D Cool Problem
RainbowQAQ · · 题解
这道题怎么这么强。
把式子改一改得:
有:
推一下式子就有了:
所以:
求出
#include <bits/stdc++.h>
#define LL long long
#define int LL
#define pb push_back
#define PII pair<int, int>
#define i64 __int128
#define YY puts("Yes"), exit(0)
#define NN puts("No"), exit(0)
using namespace std;
const int Mod = 998244353;
const int Inf = 0x3f3f3f3f;
const LL InfLL = 0x3f3f3f3f3f3f3f3f;
char buf[1 << 21], *p1 = buf, *p2 = buf;
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//#define getchar() gc()
LL read() {
LL s = 0; char ch = getchar(); bool fu = false;
while (ch < '0' || ch > '9') ch == '-' ? fu = true : 0, ch = getchar();
while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return fu ? -s : s;
}
const int N = 1e5 + 10;
int n, x, y;
i64 calc(i64 t) {
return (t * t + (x - y) * t + (i64)n * x * y) / (2 * x);
}
inline void Main() {
n = read(), x = read(), y = read();
string s; cin >> s;
bitset<N> f1, f0, g1, g0; // f 存正数,g 存负数
f0.set(0), g0.set(0);
for (auto ch : s) {
bitset<N> nf1, nf0, ng1, ng0;
if (ch != '0') {
nf1 |= g0;
nf0 |= g1;
ng1 |= f0;
ng0 |= f1;
}
if (ch != '1') {
nf1 |= f1 << 1;
nf0 |= f0 << 1;
ng1 |= g1 >> 1;
ng0 |= g0 >> 1;
}
nf0[0] = nf0[0] | ng0[0];
ng0[0] = nf0[0] | ng0[0];
nf1[0] = nf1[0] | ng1[0];
ng1[0] = nf1[0] | ng1[0];
f0 = nf0, g0 = ng0;
f1 = nf1, g1 = ng1;
}
vector<i64> ans;
for (int i = 0; i <= n; ++i) {
if (f0[i]) ans.push_back(calc(i * x));
if (f1[i]) ans.push_back(calc(i * x + y));
}
for (int i = 1; i <= n; ++i) {
if (g0[i]) ans.push_back(calc(-i * x));
if (g1[i]) ans.push_back(calc(-i * x + y));
}
sort(ans.begin(), ans.end());
ans.erase(unique(ans.begin(), ans.end()), ans.end());
LL Ans = 0;
for (auto it : ans)
Ans = (Ans + (it % Mod + Mod)) % Mod;
printf("%lld\n", Ans);
}
signed main() {
// freopen("input.in", "r", stdin);
// ios::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
int T = read();
while (T--)
Main();
return 0;
}