QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#702669#9536. Athlete Welcome Ceremonyucup-team3510#WA 1ms6180kbC++141.6kb2024-11-02 16:23:182024-11-02 16:23:18

Judging History

This is the latest submission verdict.

  • [2024-11-02 16:23:18]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 6180kb
  • [2024-11-02 16:23:18]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int p=1e9+7;
int n,q,dp[311][311][311][4],sum[311][311][311];
char s[311];
int main()
{
	scanf("%d%d",&n,&q);scanf("%s",s+1);
	dp[0][0][0][0]=1;
	int cnt[3]={0,0,0};
	for(int i=1;i<=n;++i)if(s[i]!='?')
	{
		++cnt[s[i]-'a'];
	}
	for(int a=0;a<n;++a)
	{
		for(int b=0;a+b<n;++b)
		{
			for(int c=0;a+b+c<n;++c)
			{
				int i=a+b+c;
				for(int o=0;o<=3;++o)if(dp[a][b][c][o])
				{
					if((s[i+1]=='a'||s[i+1]=='?')&&o!=1)
					{
						dp[a+1][b][c][1]=(dp[a+1][b][c][1]+dp[a][b][c][o])%p;
					}
					if((s[i+1]=='b'||s[i+1]=='?')&&o!=2)
					{
						dp[a][b+1][c][2]=(dp[a][b+1][c][2]+dp[a][b][c][o])%p;
					}
					if((s[i+1]=='c'||s[i+1]=='?')&&o!=3)
					{
						dp[a][b][c+1][3]=(dp[a][b][c+1][3]+dp[a][b][c][o])%p;
					}
				}
			}
		}
	}
	for(int a=0;a<=n;++a)for(int b=0;a+b<=n;++b)for(int o=0;o<=3;++o)
	{
		int c=n-a-b;
		sum[a][b][c]=(sum[a][b][c]+dp[a][b][c][o])%p;
	}
	for(int a=0;a<=n;++a)
	{
		for(int b=0;b<=n;++b)
		{
			for(int c=0;c<=n;++c)
			{
				if(a)
				{
					sum[a][b][c]=(sum[a-1][b][c]+sum[a][b][c])%p;
				}
			}
		}
	}
	for(int a=0;a<=n;++a)
	{
		for(int b=0;b<=n;++b)
		{
			for(int c=0;c<=n;++c)
			{
				if(b)
				{
					sum[a][b][c]=(sum[a][b-1][c]+sum[a][b][c])%p;
				}
			}
		}
	}
	for(int a=0;a<=n;++a)
	{
		for(int b=0;b<=n;++b)
		{
			for(int c=0;c<=n;++c)
			{
				if(c)
				{
					sum[a][b][c]=(sum[a][b][c-1]+sum[a][b][c])%p;
				}
			}
		}
	}
	while(q--)
	{
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		x+=cnt[0];y+=cnt[1];z+=cnt[2];
		printf("%d\n",(sum[x][y][z]%p+p)%p);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6112kb

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

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

input:

1 1
?
0 1 1

output:

2

result:

ok single line: '2'

Test #4:

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

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: 0ms
memory: 6180kb

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'