QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#699521 | #9536. Athlete Welcome Ceremony | ucup-team073# | WA | 33ms | 91592kb | C++23 | 3.0kb | 2024-11-02 09:33:34 | 2024-11-02 09:33:35 |
Judging History
answer
#include <bits/stdc++.h>
#define mpr make_pair
#define int long long
#define pb push_back
#define pii pair<int,int>
#define st first
#define nd second
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar())f^=ch=='-';
for(;isdigit(ch);ch=getchar())x=x*10+(ch^48);
return f?x:-x;
}
mt19937 rnd(time(0));
const int mo=1e9+7;
inline int qpow(int x,int t){
int ret=1;
for(;t;t>>=1,x=x*x%mo)if(t&1)ret=ret*x%mo;
return ret;
}
inline void red(int &x){x>=mo?x-=mo:0;}
inline void chmin(int &x,int y){x=min(x,y);}
inline void chmax(int &x,int y){x=max(x,y);}
const int N=305;
int f[3][N][N],g[3][N][N],res[N][N][N],n,cnt,q;
int sum[N][N][N];
char str[N];
void solve(){
n=read(),q=read();
scanf("%s",str+1);
memset(f,0,sizeof(f));
memset(g,0,sizeof(g));
auto id=[&](char x)->int{return x-'a';};
if(str[1]=='?'){
cnt=1;
g[0][0][0]=1;
g[1][1][0]=1;
g[2][0][1]=1;
}
else{
int t=id(str[1]);
if(t==0)g[0][0][0]=1;
if(t==1)g[1][0][0]=1;
if(t==2)g[2][0][0]=1;
}
for(int i=2;i<=n;++i){
memset(f,0,sizeof(f));
if(str[i]=='?'){
++cnt;
for(int A=0;A<3;++A){
for(int x=0;x<=cnt;++x){
for(int y=0;y<=cnt;++y){
if(A!=0)red(f[0][x][y]+=g[A][x][y]);
if(A!=1)red(f[1][x+1][y]+=g[A][x][y]);
if(A!=2)red(f[2][x][y+1]+=g[A][x][y]);
}
}
}
}
else{
int t=id(str[i]);
// memcpy(f[t],g[t],sizeof(f[t]));
for(int A=0;A<=cnt;++A)for(int B=0;B<=cnt;++B){
for(int c=0;c<3;++c)if(c!=t){
red(f[t][A][B]+=g[c][A][B]);
}
}
}
// printf("round-%lld:\n\n",i);
// for(int A=0;A<=cnt;++A)for(int B=0;A+B<=cnt;++B){
// for(int t=0;t<3;++t)
// printf("f[%lld][%lld][%lld][%lld]=%lld\n",t,cnt-A-B,A,B,f[t][A][B]);
// }
// puts("");
// puts("");
memcpy(g,f,sizeof(f));
}
for(int x=0;x<=cnt;++x)for(int y=0;x+y<=cnt;++y){
for(int t=0;t<3;++t)red(res[cnt-x-y][x][y]+=g[t][x][y]);
}
for(int i=0;i<=cnt;++i){
for(int x=0;x<=cnt;++x)for(int y=0;y<=cnt;++y){
sum[i][x][y]=res[i][x][y];
if(x>=1)red(sum[i][x][y]+=sum[i][x-1][y]);
if(y>=1)red(sum[i][x][y]+=sum[i][x][y-1]);
if(x>=1&&y>=1)red(sum[i][x][y]-=sum[i][x-1][y-1]);
}
for(int x=0;x<=cnt;++x)for(int y=0;y<=cnt;++y){
if(i>=1)red(sum[i][x][y]+=sum[i-1][x][y]);
}
}
while(q--){
int A=min(read(),cnt),B=min(read(),cnt),C=min(read(),cnt);
printf("%lld\n",sum[A][B][C]);
}
}
signed main(){
// freopen("test.out","w",stdout);
for(int cas=1;cas--;)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 12880kb
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: 16164kb
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: 0ms
memory: 10636kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 4ms
memory: 11348kb
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: 0
Accepted
time: 0ms
memory: 15120kb
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 16 11 16 11 16 16 5 11 0
result:
ok 10 lines
Test #6:
score: 0
Accepted
time: 14ms
memory: 14904kb
input:
50 100 ?abacbacab?cbcbcb?acabcbabcbcacbababc?caba?acacbca 8 3 8 2 4 8 8 7 3 0 9 2 10 8 7 7 6 5 4 10 2 6 9 3 3 6 6 9 10 8 2 5 8 8 1 0 3 5 0 1 0 6 5 0 8 6 5 5 1 7 9 7 7 10 4 7 5 6 6 4 10 1 2 4 1 7 10 0 8 7 6 3 1 9 1 4 7 2 8 4 0 8 6 1 5 10 4 5 8 2 5 8 4 4 5 9 5 2 1 1 10 9 4 10 1 8 4 3 8 9 9 8 0 1 0 8 0...
output:
8 8 8 0 8 8 6 8 8 8 8 0 0 0 1 8 4 8 8 8 2 4 1 8 1 6 0 2 8 6 8 8 1 4 2 8 8 0 0 8 2 0 8 8 8 4 8 8 8 8 2 0 0 4 8 8 1 8 7 6 7 0 8 8 8 0 4 7 8 4 0 8 0 4 8 8 8 7 8 4 7 2 8 8 8 0 2 2 8 8 8 4 4 0 8 0 8 8 1 1
result:
ok 100 lines
Test #7:
score: 0
Accepted
time: 11ms
memory: 34396kb
input:
50 100 b????????bca?????c?b??ca?acac?b?b???ca?ab???a?a??? 35 43 36 12 49 47 7 11 34 38 44 22 42 17 10 49 8 38 18 26 44 6 18 14 28 29 6 48 32 47 29 15 48 1 5 33 24 17 18 10 27 32 19 10 34 2 23 9 14 24 39 46 12 34 9 49 26 21 8 46 43 43 3 31 16 2 8 27 7 24 41 35 17 25 31 0 13 47 24 31 23 33 40 30 36 39...
output:
34272000 31599360 497244 34272000 17637520 12290752 34272000 93044 415832 34272000 34272000 0 34272000 16360704 27933952 0 34272000 33886976 7896832 12290752 718 24 0 34272000 34272000 0 34272000 34272000 34272000 32254720 0 5666944 34256640 34272000 34272000 12290752 30493248 34256640 20630016 0 10...
result:
ok 100 lines
Test #8:
score: 0
Accepted
time: 23ms
memory: 14872kb
input:
100 1000 c?cbababcabacbacbacacbacabcbabababacababcbcab?cbabacbacbcbcacbab?bcabcbcababcacbabacbcb?babcbab?baca 13 11 4 4 17 20 14 5 2 16 14 15 8 12 17 19 5 11 5 17 12 20 7 6 19 10 1 6 5 0 13 1 9 7 17 1 20 4 16 11 12 18 19 2 16 18 1 11 19 16 3 7 1 0 6 9 16 6 9 16 6 20 7 0 16 20 1 2 8 16 5 20 18 14 18 ...
output:
16 15 14 16 16 16 16 16 8 2 16 8 16 16 16 16 16 2 16 16 16 0 1 16 16 5 1 5 16 16 16 16 16 15 16 13 16 15 2 16 16 1 8 16 16 16 15 0 16 15 16 16 16 16 8 8 16 16 16 16 16 16 8 16 16 1 8 8 16 16 1 16 1 0 16 2 2 16 7 16 16 8 16 16 16 16 1 16 14 16 16 16 16 5 16 16 14 16 11 16 15 11 2 1 8 16 16 7 16 5 16 ...
result:
ok 1000 lines
Test #9:
score: -100
Wrong Answer
time: 33ms
memory: 91592kb
input:
100 1000 ?????c??????????????????????????b???a????a?????????????????????????c???????????????????????????????? 43 38 20 27 40 32 39 27 33 28 50 43 50 3 46 38 46 14 42 48 10 45 25 28 49 10 49 38 17 42 41 49 22 41 18 44 46 47 25 17 44 35 34 43 22 47 42 32 32 44 40 36 41 24 45 38 45 49 44 18 42 34 32 43...
output:
-4509524379 -856010171 -880338078 -143292136541 10104 219100551 -2520715318 -235781478 -7096153825 659694548 -63795713385 -10894079575 -118808221329 182802705 -784561396 -148061308725 -100202419503 -5096082622 -259106005992 -36712777635 -33421304409 -247904346887 -41542189868 -19290650345 -591403819...
result:
wrong answer 1st lines differ - expected: '490475656', found: '-4509524379'