QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734698#9536. Athlete Welcome Ceremonyxly_tyty#WA 4ms9704kbC++232.2kb2024-11-11 14:17:172024-11-11 14:17:18

Judging History

This is the latest submission verdict.

  • [2024-11-11 14:17:18]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 9704kb
  • [2024-11-11 14:17:17]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10,mod=1e9+7;
string s;
int n,m,a[N],w;
int dp[2][305][305][3];
int fa[305][305],fb[305][305];
void solve() {
	cin>>n>>m;
	cin>>s;
	s=" "+s;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='a')a[i]=0;
		else if(s[i]=='b')a[i]=1;
		else if(s[i]=='c')a[i]=2;
		else a[i]=-1,w++;
	}
	int ty=0;
	for(int i=1;i<=n;i++)
	{
		ty^=1;
		if(i==1)
		{
			if(a[i]!=-1)dp[ty][0][0][a[i]]=1;
			else dp[ty][0][0][2]=1,dp[ty][1][0][0]=1,dp[ty][0][1][1]=1;
		}
		else{
			if(a[i]!=-1)
			{
			for(int j=0;j<=300;j++)
			{
				for(int k=0;k<=300;k++)
				{
					for(int p=0;p<=2;p++)dp[ty][j][k][p]=0;
					dp[ty][j][k][a[i]]=(dp[ty^1][j][k][0]+dp[ty^1][j][k][1]+dp[ty^1][j][k][2]-dp[ty^1][j][k][a[i]]+mod)%mod;
				}
			}
			}
			else{
				for(int j=0;j<=300;j++)
				{
					for(int k=0;k<=300;k++)
					{
						for(int p=0;p<=2;p++)dp[ty][j][k][p]=0;
						if(j-1>=0)dp[ty][j][k][0]=(dp[ty^1][j-1][k][1]+dp[ty^1][j-1][k][2])%mod;
						if(k-1>=0)dp[ty][j][k][1]=(dp[ty^1][j][k-1][2]+dp[ty^1][j][k-1][0])%mod;
						dp[ty][j][k][2]=(dp[ty^1][j][k][1]+dp[ty^1][j][k][0])%mod;
					}
				}
			}
		}
	}
	for(int i=0;i<=300;i++)
	{
		for(int j=0;j<=i;j++)
		{
			for(int p=0;p<=2;p++)
			{
				fa[i][j]=(fa[i][j]+dp[ty][j][i-j][p])%mod;
				fa[i][j]%=mod;
			}
		}
		for(int j=0;j<=300;j++)fa[i][j]=(fa[i][j]+fa[i][j-1])%mod;
	}
	for(int i=0;i<=300;i++)
	{
		for(int j=0;j<=i;j++)
		{
			for(int p=0;p<=2;p++)
			{
				fb[i][j]=(fb[i][j]+dp[ty][i-j][j][p])%mod;
			}
		}
		for(int j=0;j<=300;j++)fb[i][j]=(fb[i][j]+fb[i][j-1])%mod;
	}
	//cout<<fa[1][1]<<endl;
	for(int i=1;i<=m;i++)
	{
		int x,y,z;cin>>x>>y>>z;
		int ans=0;
		for(int k=0;k<=min(w,z);k++)
		{
			int f=w-k;
			if(f>x+y||!f)continue;
			if(x&&y)ans=(ans-fa[f][f]+fa[f][x]+fb[f][y]+mod)%mod;
			else if(y)ans=(ans+fb[f][f]-fb[f][f-1]+mod)%mod;
			else if(x)ans=(ans+fa[f][f]-fa[f][f-1]+mod)%mod;
			//if(ans==1)cout<<f<<endl;
		}
		cout<<ans<<endl;
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t = 1;
	// cin >> t;
	while(t --) {
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 9704kb

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: 2ms
memory: 9400kb

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

input:

1 1
?
0 1 1

output:

1

result:

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