QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722260 | #9536. Athlete Welcome Ceremony | xuzhihaodedie# | WA | 2ms | 9936kb | C++14 | 2.1kb | 2024-11-07 18:21:51 | 2024-11-07 18:21:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
#define PII pair<int,int>
//#define endl "\n"
#define lson 2*p
#define rson 2*p+1
const int N=300+1;
const int mod=1e9+7;
int dp[2][N][N][4];
int sum[N][N];
void add(int &x,int y) {
x+=y;
if(x>=mod) x-=mod;
}
void solve() {
int n,q;
cin>>n>>q;
string s;
cin>>s;
s="?"+s;
map<char,int> mp;
mp['a']=1,mp['b']=2,mp['c']=3;
int cnt=0;
for(int i=1;i<=n;i++) if(s[i]=='?') cnt++;
if(s[1]=='?') {
dp[1][1][0][1]=1;
dp[1][0][1][2]=1;
dp[1][0][0][3]=1;
} else {
dp[1][0][0][mp[s[1]]]=1;
}
for(int i=2;i<=n;i++) {
memset(dp[i&1],0,sizeof dp[i&1]);
for(int j=0;j<=i;j++) {
for(int k=0;j+k<=i;k++) {
if(s[i]!='?') {
int x=mp[s[i]];
if(x!=1) add(dp[i&1][j][k][x],dp[(i-1)&1][j][k][1]);
if(x!=2) add(dp[i&1][j][k][x],dp[(i-1)&1][j][k][2]);
if(x!=3) add(dp[i&1][j][k][x],dp[(i-1)&1][j][k][3]);
} else {
for(int l=1;l<=3;l++) {
int x,y;
if(l==1) x=2,y=3;
else if(l==2) x=1,y=3;
else x=1,y=2;
if((j-(l==1))<0||(k-(l==2))<0) continue;
add(dp[i&1][j][k][l],dp[(i-1)&1][j-(l==1)][k-(l==2)][x]);
add(dp[i&1][j][k][l],dp[(i-1)&1][j-(l==1)][k-(l==2)][y]);
}
}
}
}
}
for(int i=0;i<=cnt;i++) {
for(int j=0;j<=cnt;j++) {
add(sum[i][j],dp[n&1][i][j][1]);
add(sum[i][j],dp[n&1][i][j][2]);
add(sum[i][j],dp[n&1][i][j][3]);
}
for(int j=1;j<=cnt;j++) {
add(sum[i][j],sum[i][j-1]);
}
}
while(q--) {
int x,y,z;
cin>>x>>y>>z;
int ans=0;
for(int i=0;i<=x;i++) {
int j=cnt-z-i;
if(j<0||j>y) continue;
add(ans,(sum[i][y]-sum[i][j-1]+mod)%mod);
}
cout<<ans<<endl;
// ans=0;
// for(int i=0;i<=x;i++) {
// for(int j=0;j<=y;j++) {
// int k=cnt-i-j;
// if(k>z) continue;
// ans=(ans+dp[n][i][j][1])%mod;
// ans=(ans+dp[n][i][j][2])%mod;
// ans=(ans+dp[n][i][j][3])%mod;
// }
// }
// cout<<ans<<endl;
}
}
signed main() {
// ios::sync_with_stdio(false);
// cin.tie(0),cout.tie(0);
int T=1;
// cin>>T;
while(T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9484kb
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: 9496kb
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: 5648kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 9936kb
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'