QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#723512 | #9536. Athlete Welcome Ceremony | ustcwaitme | WA | 187ms | 225976kb | C++23 | 2.4kb | 2024-11-07 22:39:52 | 2024-11-07 22:39:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=301,mod=1e9+7;
int dp[3][N][N][N];
ll s[N][N][N];
void solve()
{
int n,q;
cin>>n>>q;
string ss;cin>>ss;
int cnt=0;
if(ss[0]=='a') dp[0][0][0][0]=1;
else if(ss[0]=='b') dp[1][0][0][0]=1;
else if(ss[0]=='c') dp[2][0][0][0]=1;
else dp[0][1][0][0]=dp[1][0][1][0]=dp[2][0][0][1]=1,cnt++;
for(int i=1;i<n;i++)
{
if(ss[i]=='?') cnt++;
for(int t1=0;t1<=cnt;t1++)
for(int t2=0;t2+t1<=cnt;t2++)
{
int t3=cnt-t1-t2;
if(ss[i]=='?')
{
if(t1) dp[0][t1][t2][t3]=(dp[1][t1-1][t2][t3]+dp[2][t1-1][t2][t3])%mod;
if(t2) dp[1][t1][t2][t3]=(dp[0][t1][t2-1][t3]+dp[2][t1][t2-1][t3])%mod;
if(t3) dp[2][t1][t2][t3]=(dp[0][t1][t2][t3-1]+dp[1][t1][t2][t3-1])%mod;
}
else
{
if(ss[i]=='a')
{
dp[0][t1][t2][t3]=(dp[1][t1][t2][t3]+dp[2][t1][t2][t3])%mod;
dp[1][t1][t2][t3]=dp[2][t1][t2][t3]=0;
}
if(ss[i]=='b')
{
dp[1][t1][t2][t3]=(dp[0][t1][t2][t3]+dp[2][t1][t2][t3])%mod;
dp[0][t1][t2][t3]=dp[2][t1][t2][t3]=0;
}
else
{
dp[2][t1][t2][t3]=(dp[0][t1][t2][t3]+dp[1][t1][t2][t3])%mod;
dp[0][t1][t2][t3]=dp[1][t1][t2][t3]=0;
}
}
}
}
for(int t1=0;t1<=cnt;t1++)
for(int t2=0;t1+t2<=cnt;t2++)
{
int t3=cnt-t1-t2;
s[t1][t2][t3]=(dp[0][t1][t2][t3]+dp[1][t1][t2][t3]+dp[2][t1][t2][t3])%mod;
}
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
int ans=0;
for(int k=0;k<N;k++){
ans+=s[i][j][k];ans%=mod;
if(j) s[i][j][k]=(s[i][j-1][k]+ans)%mod;
else s[i][j][k]=ans;
}
}
for(int j=0;j<N;j++){
for(int k=0;k<N;k++){
if(i) s[i][j][k]=(s[i-1][j][k]+s[i][j][k])%mod;
}
}
}
// for(int i=0;i<=300;i++)
// for(int j=0;j<=300;j++)
// for(int k=0;k<=300;k++)
// {
// if(i) s[i][j][k]+=s[i-1][j][k],s[i][j][k]%=mod;
// if(j) s[i][j][k]+=s[i][j-1][k],s[i][j][k]%=mod;
// if(k) s[i][j][k]+=s[i][j][k-1],s[i][j][k]%=mod;
// if(i&&j) s[i][j][k]=(s[i][j][k]-s[i-1][j-1][k]+mod)%mod;
// if(i&&k) s[i][j][k]=(s[i][j][k]-s[i-1][j][k-1]+mod)%mod;
// if(j&&k) s[i][j][k]=(s[i][j][k]-s[i][j-1][k-1]+mod)%mod;
// if(i&&j&&k) s[i][j][k]+=s[i-1][j-1][k-1],s[i][j][k]%=mod;
// }
while(q--)
{
int x,y,z;cin>>x>>y>>z;
cout<<s[x][y][z]<<endl;
}
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
while(t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 151ms
memory: 220032kb
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: 149ms
memory: 225976kb
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: 155ms
memory: 222672kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 187ms
memory: 220556kb
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 0 0 0 0 0 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '1', found: '0'