QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699506 | #9536. Athlete Welcome Ceremony | ucup-team3555# | WA | 1ms | 6560kb | C++20 | 2.3kb | 2024-11-02 09:27:37 | 2024-11-02 09:27:38 |
Judging History
answer
/*
I know this sky loves you
いずれ全て
変わってしまったって
空は青いだろうよ
*/
# include <bits/stdc++.h>
const int N=305,INF=0x3f3f3f3f,mod=1e9+7;
inline int read(void){
int res,f=1;
char c;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
res=c-48;
while((c=getchar())>='0'&&c<='9')
res=res*10+c-48;
return res*f;
}
int n;
int q;
int dp[N][N][N][3];
char s[N];
int cnt[N];
inline int adc(int a,int b){return (a+b>=mod)?(a+b-mod):(a+b);}
inline int dec(int a,int b){return (a<b)?(a-b+mod):(a-b);}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline void add(int &a,int b){
a=adc(a,b);
}
inline void del(int &a,int b){
a=dec(a,b);
}
int ret[N][N];
inline int sum(int *arr,int l,int r){
if(l>r) return 0;
if(l==0) return arr[r];
return dec(arr[r],arr[l-1]);
}
int tot;
int main(void){
n=read(),q=read();
scanf("%s",s+1);
for(int i=1;i<=n;++i) cnt[i]=cnt[i-1]+(s[i]=='?');
if(s[1]=='?'){
for(int i=0;i<=2;++i) dp[1][(i==0)][(i==1)][i]=1;
}else{
dp[1][0][0][s[1]-'a']=1;
}
for(int i=2;i<=n;++i){
for(int x=0;x<=cnt[i-1];++x){
for(int y=0;x+y<=cnt[i-1];++y){
for(int k=0;k<=2;++k){
if(s[i]=='?'){
for(int d=0;d<=2;++d)
if(d!=k) add(dp[i][x+(d==0)][y+(d==1)][d],dp[i-1][x][y][k]);
}else{
if(s[i]-'a'!=k)
add(dp[i][x][y][s[i]-'a'],dp[i-1][x][y][k]);
}
}
}
}
}
int lim=cnt[n];
for(int i=0;i<=lim;++i){
for(int j=0;j<=lim;++j){
ret[i][j]=(1ll*dp[n][i][j][0]+1ll*dp[n][i][j][1]+1ll*dp[n][i][j][2])%mod;
if(j) add(ret[i][j],ret[i][j-1]);
}
add(tot,ret[i][lim]);
}
// printf("tot = %d\n",tot);
while(q--){
int x=read(),y=read(),z=read();
// a > x
// b > y
// (cnt - (a+b)) > z
int ans=tot;
for(int a=0;a<=lim;++a){
if(a>x) del(ans,sum(ret[a],0,lim)); // a > x
del(ans,sum(ret[a],y+1,lim)); // b > y
del(ans,sum(ret[a],0,lim-z-a-1)); // a + b < cnt - z --> b < cnt - z - a
if(a>x) add(ans,sum(ret[a],y+1,lim)); // a > x && b > y
if(a>x) add(ans,sum(ret[a],y+1,lim)); // a > x && a + b < cnt - z
// b > y && a + b < cnt - z --> b < cnt - z - a && b > y
add(ans,sum(ret[a],y+1,lim-z-a-1));
}
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6088kb
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: 6072kb
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: 3808kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5952kb
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: 1ms
memory: 6032kb
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: -100
Wrong Answer
time: 1ms
memory: 6560kb
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 1000000005 8 8 6 8 8 8 8 0 0 3 1 8 4 8 8 8 2 4 1 8 1000000005 6 0 2 8 6 8 8 1 4 2 8 8 0 999999999 8 2 0 8 8 8 4 8 8 8 8 2 0 1000000003 4 8 8 1 8 7 6 7 0 8 8 8 0 4 7 8 4 1000000003 8 1 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:
wrong answer 4th lines differ - expected: '0', found: '1000000005'