QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#701355 | #9536. Athlete Welcome Ceremony | ucup-team4938# | WA | 2ms | 14268kb | C++14 | 2.5kb | 2024-11-02 14:06:29 | 2024-11-02 14:06:31 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=310;
const int inf=1e18;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
bool Mbe;
int n,q;
int dp[maxn][maxn][maxn][3],f[maxn][maxn][maxn];
char s[maxn];
void inc(int &u,int v){((u+=v)>=mod)&&(u-=mod);}
void work(){
n=read();q=read();
scanf("%s",s+1);
int na=0,nb=0,nc=0;
for(int i=1;i<=n;i++)na+=s[i]=='a';
for(int i=1;i<=n;i++)nb+=s[i]=='b';
for(int i=1;i<=n;i++)nc+=s[i]=='c';
dp[0][0][0][0]=1;
for(int i=0;i<n;i++){
for(int j=0;i+j<n;j++){
for(int k=0;i+j+k<n;k++){
for(int op=0;op<3;op++)if(dp[i][j][k][op]){
// cout<<i<<" "<<j<<" "<<k<<" "<<op<<" "<<dp[i][j][k][op]<<"\n";
int id=i+j+k+1;
if(s[id]=='a'||s[id]=='?'){
if(id==1||op!=0){
inc(dp[i+1][j][k][0],dp[i][j][k][op]);
}
}
if(s[id]=='b'||s[id]=='?'){
if(id==1||op!=1){
inc(dp[i][j+1][k][1],dp[i][j][k][op]);
}
}
if(s[id]=='c'||s[id]=='?'){
if(id==1||op!=2){
inc(dp[i][j][k+1][2],dp[i][j][k][op]);
}
}
}
}
}
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
int k=n-i-j;
f[i][j][k]=(dp[i][j][k][0]+dp[i][j][k][1]+dp[i][j][k][2])%mod;
// if(f[i][j][k])cout<<i<<" "<<j<<" "<<k<<" "<<f[i][j][k]<<"\n";
}
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=n-i-j;k<=n;k++){
inc(f[i][j][k+1],f[i][j][k]);
}
}
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=n-i-j;k<=n;k++){
inc(f[i][j+1][k],f[i][j][k]);
}
}
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=n-i-j;k<=n;k++){
inc(f[i+1][j][k],f[i][j][k]);
}
}
}
while(q--){
int u=read()+na,v=read()+nb,w=read()+nc;
// int ans=0;
// for(int i=0;i<=u;i++){
// for(int j=0;j<=v;j++){
// for(int k=0;k<=w;k++)inc(ans,f[i][j][k]);
// }
// }
// printf("%lld\n",ans);
printf("%lld\n",f[u][v][w]);
}
}
// \
444
bool Med;
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
T=1;
while(T--)work();
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 10200kb
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: 10092kb
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: 1ms
memory: 5916kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 2ms
memory: 14208kb
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 1 1 1 0 1 1 1 1
result:
ok 10 lines
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 14268kb
input:
10 10 ?c?c?cbac? 10 5 1 5 8 7 9 2 6 5 7 1 5 2 6 5 6 5 5 10 3 9 1 10 2 5 9 1 2 9
output:
16 0 11 16 11 16 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '16', found: '0'