QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#704505 | #9536. Athlete Welcome Ceremony | ucup-team134# | WA | 12ms | 325512kb | C++17 | 2.4kb | 2024-11-02 20:06:22 | 2024-11-02 20:06:23 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128
using namespace std;
mt19937 rng(time(NULL));
const int mod=1e9+7; //998244353
int add(int a,int b){
a+=b;
if(a>=mod)
a-=mod;
return a;
}
int sub(int a,int b){
a-=b;
if(a<0)
a+=mod;
return a;
}
int mul(int a,int b){
return (long long)a*b%mod;
}
int pwrmod(int x,int k){
int ans=1;
for(;k;k>>=1,x=mul(x,x))
if(k&1)
ans=mul(ans,x);
return ans;
}
const int N=301;
int dp[N][N][N][3];
string a;
int cnt[N],n;
int cc[N][N][N];
int qm;
int calc(int x,int y,int i,int l){
if(x<0||y<0)return 0;
int u=cnt[i];
if(a[i]=='?')u--;
int z=(qm-u-x-y);
if(z<0)return 0;
if(i==n){
assert(x==0&&y==0&&z==0);
return 1;
}
if(dp[x][y][i][l]!=-1)return dp[x][y][i][l];
if(a[i]!='?'){
if(a[i]-'a'==l&&i!=0){
return dp[x][y][i][l]=0;
}
return dp[x][y][i][l]=calc(x,y,i+1,a[i]-'a');
}
dp[x][y][i][l]=0;
for(int j=0;j<3;j++){
if(i!=0&&j==l)continue;
if(j==0){
dp[x][y][i][l]=add(dp[x][y][i][l],calc(x-1,y,i+1,j));
}
if(j==1){
dp[x][y][i][l]=add(dp[x][y][i][l],calc(x,y-1,i+1,j));
}
if(j==2){
dp[x][y][i][l]=add(dp[x][y][i][l],calc(x,y,i+1,j));
}
}
return dp[x][y][i][l];
}
int main()
{
ios;
int q;
cin >> n >> q;
cin >> a;
memset(dp,-1,sizeof dp);
bool ok=1;
for(int i=0;i<n;i++){
if(a[i]=='?')cnt[i]++;
if(i)cnt[i]+=cnt[i-1];
if(i&&a[i]!='?'&&a[i-1]!='?'&&a[i]==a[i-1])ok=0;
}
cnt[n]=cnt[n-1];
if(!ok){
for(int i=0;i<q;i++){
printf("0\n");
}
return 0;
}
qm=cnt[n];
for(int x=0;x<=qm;x++){
for(int y=0;y<=qm-x;y++){
int z=qm-x-y;
cc[x][y][z]=calc(x,y,0,0);
}
for(int y=0;y<=qm;y++){
for(int z=0;z<=qm;z++){
if(y){
cc[x][y][z]=add(cc[x][y][z],cc[x][y-1][z]);
}
if(z){
cc[x][y][z]=add(cc[x][y][z],cc[x][y][z-1]);
}
if(y&&z){
cc[x][y][z]=sub(cc[x][y][z],cc[x][y-1][z-1]);
}
}
}
}
for(int i=0;i<q;i++){
int x,y,z;
cin >> x >> y >> z;
int ans=0;
for(int j=0;j<=x;j++){
ans=add(ans,cc[j][y][z]);
}
printf("%i\n",ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 325512kb
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: 4ms
memory: 325360kb
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: 3ms
memory: 323772kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 12ms
memory: 323788kb
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 1 0 0 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '1', found: '0'