QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#734669 | #9536. Athlete Welcome Ceremony | xly_tyty# | WA | 5ms | 10840kb | C++23 | 2.0kb | 2024-11-11 13:58:38 | 2024-11-11 13:58:39 |
Judging History
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;
}
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=(ans-fa[f][300]+fa[f][x]+fb[f][y]+mod)%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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 9276kb
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: 10660kb
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: 7352kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 5ms
memory: 10840kb
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 4353 1 1 0 1 4353 1 4337
result:
wrong answer 3rd lines differ - expected: '1', found: '4353'