QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#746579 | #9536. Athlete Welcome Ceremony | Suhy# | WA | 0ms | 1676kb | C++11 | 1.6kb | 2024-11-14 15:02:32 | 2024-11-14 15:02:34 |
Judging History
answer
#include<cstdio>
const int M=1000000007;
int n,q,i,j,k,l,C[3];
char s[305];
int a[2][305][305][3],b[305][305];
int gans(int l0,int r0,int l1,int r1){
if(r0>n)r0=n;
if(r1>n)r1=n;
++r0;++r1;
if(l0<0)l0=0;
if(l1<0)l1=0;
int s0=b[r0][r1]+b[l0][l1];
int s1=b[l0][r1]+b[r0][l1];
return (s0%M+M-s1%M)%M;
}
int main(){
scanf("%d%d",&n,&q);
char c;
while(c=getchar(),c!='a'&&c!='b'&&c!='c'&&c!='?');
for(i=0;i<n;++i){
if(c>='a'&&c<='c')c-='a',++C[c];
s[i]=c;
c=getchar();
}
int p=0;
if(s[0]==0||s[0]=='?')a[0][1][0][0]=1;
if(s[0]==1||s[0]=='?')a[0][0][1][1]=1;
if(s[0]==2||s[0]=='?')a[0][0][0][2]=1;
for(i=1;i<n;++i,p^=1){
for(j=0;j<n;++j)
for(k=0;k<n;++k)
for(l=0;l<3;++l)a[p^1][j][k][l]=0;
for(j=0;j<n;++j)
for(k=0;k<n;++k)
for(l=0;l<3;++l){
if(l!=0&&(s[i]==0||s[i]=='?'))(a[p^1][j+1][k][0]+=a[p][j][k][l])%=M;
if(l!=1&&(s[i]==1||s[i]=='?'))(a[p^1][j][k+1][1]+=a[p][j][k][l])%=M;
if(l!=2&&(s[i]==2||s[i]=='?'))(a[p^1][j ][k ][2]+=a[p][j][k][l])%=M;
}
}
for(i=0;i<n;++i)
for(j=0;j<n;++j)
for(k=0;k<3;++k)(b[i+1][j+1]+=a[p][i][j][k])%=M;
for(i=1;i<=n;++i)
for(j=1;j<=n;++j)(b[i][j]+=b[i-1][j])%=M;
for(i=1;i<=n;++i)
for(j=1;j<=n;++j)(b[i][j]+=b[i][j-1])%=M;
while(q--){
int x,y,z,r;
scanf("%d%d%d",&x,&y,&z);
x+=C[0];
y+=C[1];
z+=C[2];
r=x+y+z-n;
printf("%d\n",gans(x-r,x,y-r,y));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1656kb
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: 1676kb
input:
6 3 ?????? 2 2 2 2 3 3 3 3 3
output:
30 72 96
result:
ok 3 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 1628kb
input:
1 1 ? 0 1 1
output:
0
result:
wrong answer 1st lines differ - expected: '2', found: '0'