QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#710075 | #9536. Athlete Welcome Ceremony | wxgmjfhy | WA | 1ms | 8400kb | C++20 | 2.8kb | 2024-11-04 18:29:35 | 2024-11-04 18:29:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int n,q;
string s;
const int N=300;
int dp[3][N+1][N+1],g[3][N+1][N+1];
int pre[N+1][N+1];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>q;
cin>>s;
s=" "+s;
int p=0;
for(int i=1;i<=n;i++){
if(s[i]=='?'){
if(p==0){
p++;
dp[0][1][0]=(s[i-1]!='a'&&(i==n||s[i+1]!='a'));
dp[1][0][1]=(s[i-1]!='b'&&(i==n||s[i+1]!='b'));
dp[2][0][0]=(s[i-1]!='c'&&(i==n||s[i+1]!='c'));
continue;
}
for(int t=0;t<=p;t++){
for(int j=0;t+j<=p;j++){
for(int k=0;k<=2;k++){
g[k][t][j]=dp[k][t][j];
dp[k][t][j]=0;
}
}
}
p++;
if(s[i-1]!='a'&&(i==n||s[i+1]!='a')){
for(int t=1;t<=p;t++){
for(int j=0;j+t<=p;j++){
if(t-1&&s[i-1]!='?')dp[0][t][j]+=g[0][t-1][j];
if(j)dp[0][t][j]+=g[1][t-1][j];
if(p-1-(t-1+j))dp[0][t][j]+=g[2][t-1][j];
dp[0][t][j]%=mod;
}
}
}
if(s[i-1]!='b'&&(i==n||s[i+1]!='b')){
for(int t=0;t<=p;t++){
for(int j=1;j+t<=p;j++){
if(t)dp[1][t][j]+=g[0][t][j-1];
if(j-1&&s[i-1]!='?')dp[1][t][j]+=g[1][t][j-1];
if(p-1-(t+j-1))dp[1][t][j]+=g[2][t][j-1];
dp[1][t][j]%=mod;
}
}
}
if(s[i-1]!='c'&&(i==n||s[i+1]!='c')){
for(int t=0;t<=p;t++){
for(int j=0;j+t+1<=p;j++){
if(t)dp[2][t][j]+=g[0][t][j];
if(j)dp[2][t][j]+=g[1][t][j];
if(p-1-(t+j)&&s[i-1]!='?')dp[2][t][j]+=g[2][t][j];
dp[2][t][j]%=mod;
}
}
}
}
}
for(int lim=0;lim<=300;lim++){
for(int i=0;i<=lim;i++){
int x=(dp[0][i][lim-i]+dp[1][i][lim-i]+dp[2][i][lim-i])%mod;
pre[lim][i]=((i==0?0:pre[lim][i-1])+x)%mod;
}
}
for(int a,b,c;q--;){
cin>>a>>b>>c;
int mx=min(a+b,p),mn=p-c;
int ans=0;
for(int lim=mn;lim<=mx;lim++){
ans+=pre[lim][min(a,lim)]-(lim-b==0?0:pre[lim][lim-b-1]);
ans=(ans%mod+mod)%mod;
}
cout<<ans<<"\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 6408kb
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: 1ms
memory: 8400kb
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: 1ms
memory: 6396kb
input:
1 1 ? 0 1 1
output:
268016732
result:
wrong answer 1st lines differ - expected: '2', found: '268016732'