QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720917 | #9536. Athlete Welcome Ceremony | Aa | WA | 2ms | 8076kb | C++23 | 1.8kb | 2024-11-07 14:41:16 | 2024-11-07 14:41:17 |
Judging History
answer
#include <iostream>
#include <algorithm>
#define int long long
#define endl "\n"
using namespace std;
const int mod=1e9+7;
int f[2][310][310][3];
int S[310][310];
//f[i][j][k][p]表示为考虑了前i个人,用了j套a,k套b,且第i个人穿的是p的方案数
//
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n,q;
string str;
cin >> n >> q;
cin >> str;
str=" "+str;
int sum=0;
if(str[1]=='?'){
f[1][1][0][0]=1;
f[1][0][1][1]=1;
f[1][0][0][2]=1;
sum++;
}
else{
if(str[1]=='a')
f[1][0][0][0]=1;
else if(str[1]=='b')
f[1][0][0][1]=1;
else
f[1][0][0][2]=1;
}
for(int i=2;i<=n;i++){
if(str[i]=='?') sum++;
for(int j=0;j<=min(sum,300ll);j++){
for(int k=0;k<=min(sum-j,300ll);k++){
for(int p=0;p<3;p++) f[i&1][j][k][p]=0;
if(str[i]=='?'){
if(j)
f[i&1][j][k][0]=(f[i&1^1][j-1][k][1]+f[i&1^1][j-1][k][2])%mod;
if(k)
f[i&1][j][k][1]=(f[i&1^1][j][k-1][0]+f[i&1^1][j][k-1][2])%mod;
if(j+k!=sum)
f[i&1][j][k][2]=(f[i&1^1][j][k][0]+f[i&1^1][j][k][1])%mod;
}
else{
if(str[i]=='a')
f[i&1][j][k][0]=(f[i&1^1][j][k][1]+f[i&1^1][j][k][2])%mod;
else if(str[i]=='b')
f[i&1][j][k][1]=(f[i&1^1][j][k][0]+f[i&1^1][j][k][2])%mod;
else
f[i&1][j][k][2]=(f[i&1^1][j][k][0]+f[i&1^1][j][k][1])%mod;
}
}
}
}
for(int i=0;i<=300;i++){
for(int j=0;j<=300;j++){
if(j) S[i][j]=S[i][j-1];
for(int k=0;k<3;k++){
S[i][j]=(S[i][j]+f[n&1][i][j][k])%mod;
}
}
}
while(q--){
int x,y,z;
cin >> x >> y >> z;
int res=0;
for(int i=0;i<=x;i++){
int down=sum-z-i;
if(y>=down){
res=(res+S[i][y])%mod;
if(down) res=(res-S[i][down-1]+mod)%mod;
}
}
cout << res << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7912kb
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: 8076kb
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: 2ms
memory: 6596kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 6312kb
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 9301354 9301370 1 1 -990698654 1 9308522 1 9301370
result:
wrong answer 2nd lines differ - expected: '1', found: '9301354'