QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734663#9536. Athlete Welcome Ceremonyxly_tyty#WA 3ms10768kbC++232.3kb2024-11-11 13:52:212024-11-11 13:52:21

Judging History

This is the latest submission verdict.

  • [2024-11-11 13:52:21]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 10768kb
  • [2024-11-11 13:52:21]
  • 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++;
	}
	//for(int i=1;i<=n;i++)cout<<a[i]<<' ';cout<<endl;
	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++)
				{
					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;
					for(int p=0;p<=2;p++)
					{
						if(a[i]!=p)dp[ty][j][k][p]=0;
					}
				}
			}
			}
			else{
				dp[ty][0][0][0]=0;
				dp[ty][0][0][1]=0;
				dp[ty][0][0][2]=0;
				for(int j=0;j<=300;j++)
				{
					for(int k=0;k<=300;k++)
					{
						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<=2;i++)
	{
		for(int j=0;j<=2;j++)cout<<i<<' '<<j<<' '<<dp[ty][i][j][2]<<endl;
	}*/
	for(int i=0;i<=300;i++)
	{
		for(int j=0;j<=i;j++)
		{
			for(int p=0;p<=2;p++)
			{
				fa[i][j]+=dp[ty][j][i-j][p];
				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]+=dp[ty][i-j][j][p];
				fb[i][j]%=mod;
			}
		}
		for(int j=0;j<=300;j++)fb[i][j]=(fb[i][j]+fb[i][j-1])%mod;
	}
	for(int i=1;i<=m;i++)
	{
		int x,y,z;cin>>x>>y>>z;
		int ans=0;
		for(int k=0;k<=z;k++)
		{
			int f=w-k;
			if(f>x+y)continue;
			ans+=fa[f][300]%mod;
			ans-=(fa[f][300]-fa[f][x])%mod;
			ans-=(fb[f][300]-fb[f][y])%mod;
			ans+=2*mod;
			ans%=mod;
		}
		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: 0ms
memory: 10768kb

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

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: 3ms
memory: 9000kb

input:

1 1
?
0 1 1

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 9248kb

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
390734008
390738360
1
1
390734007
1
390734120
1
390738344

result:

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