QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#778918 | #9536. Athlete Welcome Ceremony | ZycK | WA | 1ms | 7728kb | C++14 | 3.5kb | 2024-11-24 16:46:56 | 2024-11-24 16:46:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 310;
const int mod = 1e9 + 7;
int n, q;
string s;
LL c[N];
// LL dp[2][N][N][3];
LL dp[2][N][N][3];
LL sum[N][N];
int main()
{
cin >> n >> q;
cin >> s;
s = " " + s;
for(int i = 1; i <= n; i ++) c[i] = c[i - 1] + (s[i] == '?');
for(int i = 1; i <= n; i ++)
{
if(i == 1)
{
if(s[i] == '?')
{
dp[i][1][0][0] = 1;
dp[i][0][1][1] = 1;
dp[i][0][0][2] = 1;
}
else
{
dp[i][0][0][s[i] - 'a'] = 1;
}
}
else
{
for(int j = 0; j <= n; j ++)
for(int k = 0; k <= n; k ++)
for(int t = 0; t < 3; t ++)
dp[i & 1][j][k][t] = 0;
for(int j = 0; j <= c[i]; j ++)
for(int k = 0; k <= c[i] - j; k ++)
{
int cnt = c[i] - j - k;
assert(cnt >= 0 && cnt <= c[i]);
if(s[i] == 'a')
{
dp[i & 1][j][k][0] = (dp[(i + 1) & 1][j][k][1] + dp[(i + 1) & 1][j][k][2]) % mod;
dp[i & 1][j][k][1] = 0;
dp[i & 1][j][k][2] = 0;
}
else if(s[i] == 'b')
{
dp[i & 1][j][k][0] = 0;
dp[i & 1][j][k][1] = (dp[(i + 1) & 1][j][k][0] + dp[(i + 1) & 1][j][k][2]) % mod;
dp[i & 1][j][k][2] = 0;
}
else if(s[i] == 'c')
{
dp[i & 1][j][k][0] = 0;
dp[i & 1][j][k][1] = 0;
dp[i & 1][j][k][2] = (dp[(i + 1) & 1][j][k][0] + dp[(i + 1) & 1][j][k][1]) % mod;
}
else
{
for(int t = 0; t < 3; t ++)
{
LL &v = dp[i & 1][j][k][t];
v = 0;
for(int la = 0; la < 3; la ++)
if(la != t)
{
if(t == 0) v = (v + dp[(i + 1) & 1][j - 1][k][la]) % mod;
else if(t == 1) (v = v + dp[(i + 1) & 1][j][k - 1][la]) % mod;
else v = (v + dp[(i + 1) & 1][j][k][la]) % mod;
}
}
}
}
}
}
for(int a = 0; a <= c[n]; a ++)
{
for(int b = 0; b <= c[n] - a; b ++)
{
for(int t = 0; t < 3; t ++) sum[a][b] = (sum[a][b] + dp[n & 1][a][b][t]) % mod;
sum[a][b] = (sum[a][b] + sum[a][b - 1]) % mod;
}
}
while(q --)
{
LL res = 0;
int x, y, z;
cin >> x >> y >> z;
for(int t = 0; t <= x; t ++)
{
int l = c[n] - t - z, r = y;
if(l > r) continue;
LL add = sum[t][r] - sum[t][l - 1];
add = (add % mod + mod) % mod;
res = (res + add) % mod;
}
cout << res << endl;
}
}
/*
6 3
a?b??c
2 2 2
1 1 1
1 0 2
6 3
??????
2 2 2
2 3 3
3 3 3
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7728kb
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: 5628kb
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: 5612kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 5684kb
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 992217543 992217559 0 0 992217543 0 992224103 0 992217559
result:
wrong answer 2nd lines differ - expected: '1', found: '992217543'