QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#746662#9536. Athlete Welcome CeremonySuhy#WA 0ms3720kbC++111.6kb2024-11-14 15:12:572024-11-14 15:12:57

Judging History

This is the latest submission verdict.

  • [2024-11-14 15:12:57]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3720kb
  • [2024-11-14 15:12:57]
  • Submitted

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+1;++i)
    for(j=1;j<=n+1;++j)(b[i][j]+=b[i-1][j])%=M;
    for(i=1;i<=n+1;++i)
    for(j=1;j<=n+1;++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: 1688kb

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: 1700kb

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: 1668kb

input:

1 1
?
0 1 1

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 0ms
memory: 1632kb

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: 3720kb

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: 2000kb

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
8
8
8
8
8
0
4
0
1
8
4
8
8
8
3
4
1
8
1
8
8
8
8
8
8
8
4
4
8
8
8
0
0
8
8
0
8
8
8
4
8
8
8
8
8
0
0
4
8
8
1
8
7
8
7
0
8
8
8
0
4
7
8
4
0
8
0
4
8
8
8
7
8
4
7
8
8
8
8
0
8
3
8
8
8
4
4
3
8
8
8
8
1
4

result:

wrong answer 7th lines differ - expected: '6', found: '8'