QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733172 | #8334. Gene | zackyoung | WA | 1ms | 7892kb | C++17 | 1.8kb | 2024-11-10 17:31:25 | 2024-11-10 17:31:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int P = 131;
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];
}
p[i]=p[i-1]*P;
}
}
void init2(string& t){
h2[0]=0;
for(int i=1;i<=m;i++){
h2[i]=h2[i-1]*P+t[i];
}
}
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=0,r=m+1;
while(true){
while(l+1!=r){
int mid=(l+r)>>1;
if(check(i,l+1,mid)) l=mid;
else r=mid;
}
if(r>=1&&r<=m){
l=r;
r=m+1;
cnt++;
}else if(r==m+1){
break;
}
if(cnt>k){
break;
}
}
if(cnt<=k){
ans++;
}
}
cout<<cnt<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7892kb
input:
6 4 4 1 kaki kika manu nana tepu tero kaka mana teri anan
output:
2 2 1 2
result:
wrong answer 4th numbers differ - expected: '0', found: '2'