QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716396 | #8334. Gene | xinlengweishang | WA | 2ms | 13012kb | C++20 | 2.0kb | 2024-11-06 15:08:16 | 2024-11-06 15:08:16 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define Mod 998244353
#define sushu 23
using namespace std;
char s[400][70000],t[70000];
ll f[400][70000];
ll g[70000];
ll qp[70000];
ll n,q,m,k;
ll flag;
int check(ll x,ll l ,ll r){
if(f[x][r]-f[x][l-1]*qp[l-1]==g[r]-g[l-1]*qp[l-1]) return 1;
else return 0;
}
void sslove(ll x,ll l,ll r){
// printf(" %lld %lld %lld\n",x,l,r);
if(flag>k) return ;
if(r-l+1<=2){
flag--;
for(int i=l;i<=r;i++){
if(s[x][i]!=t[i]) flag++;
}
// printf(" check : %lld %lld %lld flag=%lld\n",x,l,r,flag);
return ;
}
ll mid=(l+r)>>1;
flag--;
if(!check(x,l,mid)){
flag++;
sslove(x,l,mid);
}
if(flag>k) return ;
if(!check(x,mid+1,r)){
// for(int i=mid+1;i<=r;i++){
// printf(" %d s: %c t: %c\n",i,s[x][i],t[i]);
// }
// printf(" s: %lld t: %lld\n",f[x][r]-f[x][mid],g[r]-g[mid]);
flag++;
sslove(x,mid+1,r);
}
return ;
}
void slove(){
scanf("%lld%lld%lld%lld",&n,&q,&m,&k);
for(int i=1;i<=n;i++){
scanf("%s",s[i]+1);
f[i][0]=0;
for(int q=1;q<=m;q++){
f[i][q]=(f[i][q-1]*sushu+s[i][q]-'a'+1)%Mod;
}
}
//
// for(int i=1;i<=n;i++){
// printf("%s\n",s[i]+1);
// for(int q=1;q<=m;q++){
// printf("%d %d %lld\n",i,q,f[i][q]);
// }
// }
for(int i=1;i<=q;i++){
scanf("%s",t+1);
g[0]=0;
int ans=0;
for(int q=1;q<=m;q++){
g[q]=(g[q-1]*sushu+t[q]-'a'+1)%Mod;
// printf(" %d g[q]=%lld g[q-1]=%lld %c \n",i,g[q],g[q-1],t[q]);
}
//
// printf("%s\n",t+1);
// for(int q=1;q<=m;q++){
// printf(" %d %lld\n",q,g[q]);
// }
for(int q=1;q<=n;q++){
if(check(q,1,m)){
ans++;
}
else{
flag=1;
sslove(q,1,m);
// printf("%d %d %d\n",i,q,flag);
if(flag<=k){
ans++;
}
}
}
printf("%d\n",ans);
}
}
int main(){
qp[0]=1;
for(int i=1;i<=600010;i++){
qp[i]=(qp[i-1]*sushu)%Mod;
}
int T=1;
while(T--) slove();
return 0;
}
/*
6 4 4 1
kaki
kika
manu
nana
tepu
tero
kaka
mana
teri
anan
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 13012kb
input:
6 4 4 1 kaki kika manu nana tepu tero kaka mana teri anan
output:
2 2 1 0
result:
ok 4 number(s): "2 2 1 0"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 12184kb
input:
8 6 7 3 delphis aduncus peronii plumbea clymene hectori griseus electra delphis helpiii perphii clumeee eleelea ddlpcus
output:
1 1 2 2 0 0
result:
wrong answer 5th numbers differ - expected: '1', found: '0'