QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737589 | #9536. Athlete Welcome Ceremony | ucup-team1412 | WA | 3ms | 16156kb | C++14 | 3.1kb | 2024-11-12 16:21:26 | 2024-11-12 16:21:28 |
Judging History
answer
//https://contest.ucup.ac/contest/1821/problem/9536?v=1
//f[i][x][y][p] : 考虑前i个字符,使用j个a,k个b,并且最后一个字符是p
#include<bits/stdc++.h>
using namespace std;
const int maxn = 305;
int n , q;
string c, s;
int f[maxn][maxn][maxn][3];
int g[maxn][maxn][maxn];
int cnt[3];
const int mod = 1e9 + 7;
signed main(){
cin >> n >> q;
cin >> c;
s = "0";
s += c;
for(int i = 1 ; i <= n;i++){
if(s[i]!='?')cnt[ (int)(s[i] - 'a') ]++;
}
if(s[1] == '?'){
f[1][2][1][0] = 1;
f[1][1][2][1] = 1;
f[1][1][1][2] = 1;
}
else{
if(s[1] == 'a')f[1][2][1][0] = 1;
if(s[1] == 'b')f[1][1][2][1] = 1;
if(s[1] == 'c')f[1][1][1][2] = 1;
}
for(int i = 2; i <= n ;i ++){
for(int x = 1 ; x <= i + 1 ; x++){
for(int y = 1 ; x + y <= i + 2; y++ ){
// cout << "fdassdas" << endl;
int z = i + 3 - x - y;
if(s[i] != '?'){
if(s[i] == 'a' && x >= 1){
//f[1][2][1][0]
f[i][x][y][0] = ( f[i - 1][x - 1][y][1] + f[i - 1][x - 1][y][2]) % mod ;
}
else if ( s[i] == 'b' && y >= 1 ){
f[i][x][y][1] = (f[i - 1][x][y - 1][0] + f[i - 1][x][y - 1][2])% mod ;
}
else if ( s[i] == 'c' && z >= 1 ){
f[i][x][y][2] = (f[i - 1][x][y][0] + f[i - 1][x][y][1] ) % mod;
}
}
else{
if(s[i - 1] != 'a' && x >= 1 ){//can select a
f[i][x][y][0] = ( f[i - 1][x - 1][y][1] + f[i - 1][x - 1][y][2]) % mod;
}
if(s[i - 1] != 'b' && y >= 1){//can select b
f[i][x][y][1] = (f[i - 1][x][y - 1][0] + f[i - 1][x][y - 1][2]) % mod;
}
if(s[i - 1] != 'c' && z >= 1){//can select c
f[i][x][y][2] = (f[i - 1][x][y][0] + f[i - 1][x][y][1] ) % mod;
}
}
}
}
}
// cout << f[6][3][3][2] << endl;
for(int x = 1 ; x <= n + 1; x++){
for(int y = 1 ;y <= n + 1; y++){
for(int z = 1 ; z <= n + 1 ; z++){
int res = 0;
for(int i = 0 ; i <= 2 ; i++){
res = ( res + f[n][x][y][i])% mod;
}
// cout << res << endl;
g[x][y][z] = (g[x-1][y][z] + g[x][y-1][z] + g[x][y][z-1] - g[x-1][y-1][z]-g[x-1][y][z-1]-g[x][y-1][z-1] + g[x-1][y-1][z-1] )%mod;
if(x + y + z == n + 3){
g[x][y][z] = (g[x][y][z] + res) % mod;
}
// cout << g[x][y][z] << endl;
}
}
}
while(q--){
int x,y,z;
cin >> x >> y >> z;
cout << g[x + 1 + cnt[0] ][y + 1 + cnt[1] ][z + 1 + cnt[2] ]<< endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11972kb
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: 11904kb
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: 1ms
memory: 5568kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 16156kb
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: -100
Wrong Answer
time: 3ms
memory: 16040kb
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:
0 0 11 16 11 16 0 0 0 0
result:
wrong answer 1st lines differ - expected: '16', found: '0'