QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733371 | #8334. Gene | zackyoung | WA | 1ms | 9716kb | C++17 | 1.9kb | 2024-11-10 18:30:08 | 2024-11-10 18:30:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int P = 131,mod=1e9+7;
typedef pair<int,int> PII;
typedef unsigned long long ull;
int n,q,m,k,ans;
string s[310];
ull h[310][60010],h2[60010],p[60010];
void init(){
p[0]=1;
for(int i=1;i<=n;i++){
h[i][1]=0;
for(int j=1;j<=m;j++){
h[i][j]=h[i][j-1]*P+s[i][j];
h[i][j]%=mod;
}
p[i]=p[i-1]*P%mod;
}
}
void init2(string& t){
h2[0]=0;
for(int i=1;i<=m;i++){
h2[i]=h2[i-1]*P+t[i];
h2[i]%=mod;
}
}
ull get1(int i,int l,int r){
return h[i][r]-h[i][l-1]*p[r-l+1];
}
ull get2(int l,int r){
return h2[r]-h2[l-1]*p[r-l+1];
}
bool check(int i,int l,int r){
return get1(i,l,r)==get2(l,r);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n>>q>>m>>k;
for(int i=1;i<=n;i++){
cin>>s[i];
s[i]=" "+s[i];
}
//预处理哈希
init();
//处理询问
while(q--){
ans=0;
string t;
cin>>t;
t=" "+t;
//对每一个t进行哈希
init2(t);
//对哈希进行二分
int cnt;
for(int i=1;i<=n;i++){
cnt=0;
int l=1,r=m;
while(true){
while(l<=r){
int mid=(l+r)>>1;
if(check(i,l,mid)){
l=mid+1;
}
else r=mid-1;
}
// cout<<t<<s[i]<<" "<<l<<"\n";
if(l>=1&&l<=m){
l+=1;
r=m;
cnt++;
}else if(l==m+1){
break;
}
if(cnt>k){
break;
}
}
if(cnt<=k){
ans++;
}
}
cout<<ans<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7944kb
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: 1ms
memory: 9716kb
input:
8 6 7 3 delphis aduncus peronii plumbea clymene hectori griseus electra delphis helpiii perphii clumeee eleelea ddlpcus
output:
1 0 1 1 1 0
result:
wrong answer 2nd numbers differ - expected: '1', found: '0'