QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713850#9536. Athlete Welcome CeremonyEMTzWA 167ms448832kbC++202.6kb2024-11-05 20:42:252024-11-05 20:42:26

Judging History

This is the latest submission verdict.

  • [2024-11-05 20:42:26]
  • Judged
  • Verdict: WA
  • Time: 167ms
  • Memory: 448832kb
  • [2024-11-05 20:42:25]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long
#define lson k<<1
#define rson (k<<1)|1
#define debug cout<<666<<endl;
using namespace std;
const int N=1e6+5;
const int M=1e9+7;
int dp[2][155][155][155][4];
int a[305][305][305];
int sum[305][305][305];
void vision()
{
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	s=" "+s+"   ";
	int all=0;
	int op=1;
	for(int i=1;i<=n;i++)
	{
		if(s[i]!='?') 
		{
			continue;
		}
		if(s[i]=='?')all++;
		for(int x=0;x<=min(n/2,all);x++)
		{
			for(int y=0;y<=min(n/2,all-x);y++)
			{
				int z=all-x-y;
				if(z<0) break;
				if(z>n/2) continue;
				for(int k=1;k<=3;k++)
				{
					int la=-1,ne=-1;
					if(s[i-1]=='a') la=1;
					if(s[i-1]=='b') la=2;
					if(s[i-1]=='c') la=3;
					if(s[i+1]=='a') ne=1;
					if(s[i+1]=='b') ne=2;
					if(s[i+1]=='c') ne=3;
					if(k==la||k==ne) continue;
					if(s[i-1]=='?')
					{
						for(int j=1;j<=3;j++)
						{
							if(k==j) continue;
							if(k==1&&x>0)dp[op][x][y][z][k]+=dp[op^1][x-1][y][z][j];
							if(k==2&&y>0)dp[op][x][y][z][k]+=dp[op^1][x][y-1][z][j];
							if(k==3&&z>0)dp[op][x][y][z][k]+=dp[op^1][x][y][z-1][j];
							dp[op][x][y][z][k]%=M;
						}
					}
					else 
					{
						if(all==1)
						{
							if(k==1&&x>0)dp[op][x][y][z][k]=1;
							if(k==2&&y>0)dp[op][x][y][z][k]=1;
							if(k==3&&z>0)dp[op][x][y][z][k]=1;
							continue;
						}
						for(int j=1;j<=3;j++)
						{
							if(k==1&&x>0)dp[op][x][y][z][k]+=dp[op^1][x-1][y][z][j];
							if(k==2&&y>0)dp[op][x][y][z][k]+=dp[op^1][x][y-1][z][j];
							if(k==3&&z>0)dp[op][x][y][z][k]+=dp[op^1][x][y][z-1][j];
							dp[op][x][y][z][k]%=M;
						}
					}
				}
			}
		}
		op^=1;
	}
	for(int i=0;i<=300;i++)
	{
		for(int j=0;j<=300;j++)
		{
			for(int z=0;z<=300;z++)
			{
				if(i+j+z!=all||i>n/2||j>n/2||z>n/2) a[i+1][j+1][z+1]=0;
				else
				{
					a[i+1][j+1][z+1]=dp[op^1][i][j][z][1]+dp[op^1][i][j][z][2]+dp[op^1][i][j][z][3];
					a[i+1][j+1][z+1]%=M;
				} 
				sum[i+1][j+1][z+1]=a[i+1][j+1][z+1]+sum[i+1][j+1][z-1+1]+sum[i+1][j-1+1][z+1]-sum[i+1][j-1+1][z-1+1]+sum[i-1+1][j+1][z+1]-sum[i-1+1][j+1][z-1+1]-sum[i-1+1][j-1+1][z+1]+sum[i-1+1][j-1+1][z-1+1];
				sum[i+1][j+1][z+1]%=M;
			}
		}
	}
//	cout<<a[1][1][1]<<"\n";
	while(m--)
	{
		
		int x,y,z;
		cin>>x>>y>>z;
		if(x+y+z<all) 
		{
			cout<<0<<"\n";
			continue;
		}
		int ans=sum[x+1][y+1][z+1];
		ans%=M;
		cout<<ans<<"\n";
	}
	return ;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t=1;
	// cin>>t;
	while(t--){
		vision();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 119ms
memory: 448612kb

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: 167ms
memory: 448832kb

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: 123ms
memory: 441332kb

input:

1 1
?
0 1 1

output:

0

result:

wrong answer 1st lines differ - expected: '2', found: '0'