QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#750061 | #9536. Athlete Welcome Ceremony | PlentyOfPenalty# | WA | 1ms | 5772kb | C++20 | 2.2kb | 2024-11-15 12:27:15 | 2024-11-15 12:27:16 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define endl '\n'
#define log(...) ((void)(0))
#endif
using namespace std;
using ll = long long;
using lf = long double;
using ull = unsigned long long;
using lll = __int128;
const int N = 311, mod = 1e9 + 7;
void Add(int &a, int t) {
a += t;
if (a >= mod) a -= mod;
}
int f[N][N][N][3], res[N][N];
string a;
int main() {
#ifdef memset0
freopen("B.in", "r", stdin);
#endif
cin.tie(0)->sync_with_stdio(0);
int n, q;
cin >> n >> q >> a;
a.insert(a.begin(), ' ');
int sig = 0;
bool t = (a[1] == '?');
sig += t;
if (a[1] == 'a' || a[1] == '?') f[1][t][0][0] = 1;
if (a[1] == 'b' || a[1] == '?') f[1][0][t][1] = 1;
if (a[1] == 'c' || a[1] == '?') f[1][0][0][2] = 1;
for (int i = 2; i <= n; ++i) {
t = (a[i] == '?');
if (a[i] == 'a' || a[i] == '?') {
for (int j = 0; j <= sig; ++j)
for (int k = 0; k <= sig; ++k) Add(f[i][j + t][k][0], f[i - 1][j][k][1]), Add(f[i][j + t][k][0], f[i - 1][j][k][2]);
}
if (a[i] == 'b' || a[i] == '?') {
for (int j = 0; j <= sig; ++j)
for (int k = 0; k <= sig; ++k) Add(f[i][j][k + t][1], f[i - 1][j][k][0]), Add(f[i][j][k + t][1], f[i - 1][j][k][2]);
}
if (a[i] == 'c' || a[i] == '?') {
for (int j = 0; j <= sig; ++j)
for (int k = 0; k <= sig; ++k) Add(f[i][j][k][2], f[i - 1][j][k][0]), Add(f[i][j][k][2], f[i - 1][j][k][1]);
}
sig += t;
}
for (int j = 0; j <= sig; ++j) {
res[j][0] = ((ll)f[n][j][0][0] + f[n][j][0][1] + f[n][j][0][2]) % mod;
for (int k = 1; k <= sig; ++k) res[j][k] = ((ll)res[j][k - 1] + ((ll)f[n][j][k][0] + f[n][j][k][1] + f[n][j][k][2])) % mod;
// for (int k = 0; k <= sig; ++k) log("Fn[%d,%d]=%d\n", j, k, f[n][j][k]);
}
while (q--) {
int x, y, z;
cin >> x >> y >> z;
int ans = 0;
for (int a = 0; a <= x && a <= sig; ++a) {
int lb = max(sig - a - z, 0), rb = y;
if (lb <= rb) {
ans = ((ans + res[a][rb])) % mod;
if (lb) ans = ((ans - res[a][lb - 1]) % mod + mod) % mod;
}
}
cout << ans << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5772kb
input:
6 3 a?b??c 2 2 2 1 1 1 1 0 2
output:
3 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
6 3 ?????? 2 2 2 2 3 3 3 3 3
output:
30 72 96
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5660kb
input:
10 10 acab?cbaca 0 2 0 1 1 2 4 2 3 1 1 1 3 5 1 0 5 2 2 2 0 1 2 5 4 3 0 1 1 3
output:
0 1 0 1 0 0 0 0 0 1
result:
wrong answer 3rd lines differ - expected: '1', found: '0'