QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#733377#8334. GenezackyoungWA 1ms7972kbC++171.8kb2024-11-10 18:31:582024-11-10 18:31:59

Judging History

你现在查看的是最新测评结果

  • [2024-11-10 18:31:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7972kb
  • [2024-11-10 18:31:58]
  • 提交

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=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<<ans<<"\n";
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7672kb

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: 7972kb

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'