QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#725535 | #9536. Athlete Welcome Ceremony | lxl# | WA | 0ms | 3896kb | C++20 | 3.4kb | 2024-11-08 18:37:41 | 2024-11-08 18:37:42 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
#define A 0
#define B 1
#define C 2
const ll mod = 1e9 + 7;
// dp[i][j][k] 表示?中有i个a,j个b,结尾为k的方案数
void solve() {
int n, q; std::cin >> n >> q;
std::string s; std::cin >> s;
std::vector dp(n + 1, std::vector(n + 1, std::vector<ll>(3, 0)));
if(s[0] == 'a') dp[0][0][A] = 1;
else if(s[0] == 'b') dp[0][0][B] = 1;
else if(s[0] == 'c') dp[0][0][C] = 1;
else {
dp[1][0][A] = 1;
dp[0][1][B] = 1;
dp[0][0][C] = 1;;
}
for(int i = 1; i < n; i++) {
std::vector<std::vector<std::vector<ll>>> t = dp;
if(s[i] == '?') {
for(int x = 0; x <= n; x++) {
for(int y = 0; y <= n; y++) {
if(x - 1 >= 0) dp[x][y][A] =( t[x - 1][y][B] + t[x - 1][y][C]) % mod;
else dp[x][y][A] = 0;
if(y - 1 >= 0) dp[x][y][B] = (t[x][y - 1][A] + t[x][y - 1][C]) % mod;
else dp[x][y][B] = 0;
dp[x][y][C] = (t[x][y][A] + t[x][y][B]) % mod;
}
}
}
else if(s[i] == 'a') {
for(int x = 0; x <= n; x++) {
for(int y = 0; y <= n; y++) {
dp[x][y][A] = (t[x][y][B] + t[x][y][C]) % mod;
dp[x][y][B] = 0;
dp[x][y][C] = 0;
}
}
}
else if(s[i] == 'b') {
for(int x = 0; x <= n; x++) {
for(int y = 0; y <= n; y++) {
dp[x][y][B] = (t[x][y][A] + t[x][y][C]) % mod;
dp[x][y][A] = 0;
dp[x][y][C] = 0;
}
}
}
else if(s[i] == 'c') {
for(int x = 0; x <= n; x++) {
for(int y = 0; y <= n; y++) {
dp[x][y][C] = (t[x][y][A] + t[x][y][B]) % mod;
dp[x][y][A] = 0;
dp[x][y][B] = 0;
}
}
}
// std::cout << '\n' << i << ": " << '\n';
// for(int x = 0; x <= n; x++) {
// for(int y = 0; y <= n; y++) {
// std::cerr << dp[x][y][A] + dp[x][y][B] + dp[x][y][C] << " ";
// }
// std::cout << '\n';
// }
}
std::vector sum(n + 1, std::vector<ll>(n + 1, 0));
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= n; j++) {
sum[i][j] = (dp[i][j][A] + dp[i][j][B] + dp[i][j][C]) % mod;
}
}
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= n; j++) {
if(i + 1 <= n) sum[i + 1][j] += sum[i][j];
sum[i][j] %= mod;
}
}
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= n; j++) {
if(j + 1 <= n) sum[i][j + 1] += sum[i][j];
sum[i][j] %= mod;
}
}
std::vector sumt(n + 1, std::vector<ll>(n + 1, 0));
for(int x = 0; x <= n; x++) {
for(int y = 0; y <= n; y++) {
sumt[x][y] = dp[x][y][A] + dp[x][y][B] + dp[x][y][C];
sumt[x][y] %= mod;
}
}
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= n; j++) {
if(i + 1 <= n) sumt[i + 1][j] += sumt[i][j];
sumt[i][j] %= mod;
}
}
int d = 0;
for(int i = 0; i < s.size(); i++) {
if(s[i] == '?') d++;
}
// for(int x = 0; x <= n; x++) {
// for(int y = 0; y <= n; y++) {
// std::cerr << dp[x][y][A] + dp[x][y][B] + dp[x][y][C] << " ";
// }
// std::cout << '\n';
// }
while(q--) {
int x, y, z;
std::cin >> x >> y >> z;
// x + y < d - z
ll ans = sum[x][y];
for(int i = 0; i <= n; i++) {
if(i > std::min(d - z - 1, x)) break;
int j = std::min(d - z - 1 - i, y);
ans -= sum[i][j];
}
std::cout << (ans % mod + mod) % mod<< '\n';
}
}
int main()
{
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
int t = 1;
// std::cin >> t;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3780kb
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: 0ms
memory: 3560kb
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: 3776kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3880kb
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 1 1 1 0 1 1 1 1
result:
ok 10 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
10 10 ?c?c?cbac? 10 5 1 5 8 7 9 2 6 5 7 1 5 2 6 5 6 5 5 10 3 9 1 10 2 5 9 1 2 9
output:
16 16 11 16 11 16 16 5 11 0
result:
ok 10 lines
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3896kb
input:
50 100 ?abacbacab?cbcbcb?acabcbabcbcacbababc?caba?acacbca 8 3 8 2 4 8 8 7 3 0 9 2 10 8 7 7 6 5 4 10 2 6 9 3 3 6 6 9 10 8 2 5 8 8 1 0 3 5 0 1 0 6 5 0 8 6 5 5 1 7 9 7 7 10 4 7 5 6 6 4 10 1 2 4 1 7 10 0 8 7 6 3 1 9 1 4 7 2 8 4 0 8 6 1 5 10 4 5 8 2 5 8 4 4 5 9 5 2 1 1 10 9 4 10 1 8 4 3 8 9 9 8 0 1 0 8 0...
output:
8 8 8 0 8 8 6 8 8 8 8 1000000001 1000000000 0 1 8 4 8 8 8 2 4 1 8 1 6 999999999 0 8 6 8 8 1000000006 4 0 8 8 1000000006 0 8 0 1000000005 8 8 8 4 8 8 8 8 0 0 0 4 8 8 1 8 7 6 7 0 8 8 8 0 4 7 8 4 0 8 0 4 8 8 8 7 8 4 7 0 8 8 8 0 0 2 8 8 8 4 4 999999999 8 999999999 8 8 1 1000000006
result:
wrong answer 12th lines differ - expected: '0', found: '1000000001'