QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791628#8334. GenerdcamelotTL 0ms3700kbC++201.6kb2024-11-28 19:57:002024-11-28 19:57:01

Judging History

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

  • [2024-11-28 19:57:01]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3700kb
  • [2024-11-28 19:57:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64=long long;
using u64=unsigned long long;
#define ll long long
const int inf=1e9;
const ll inff=1e18;
using i128=__int128;

// 分块
constexpr int base=233;
void solve(){
    int n,q,m,k;
    cin>>n>>q>>m>>k;
    int B=sqrt(m/k);
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    auto hash=[&](const string &s){
        vector<u64> res;
        for(int l=0,r;l<m;l=r){
            r=min(l+B,m);
            u64 cur=0;
            for(int i=l;i<r;i++){
                cur=cur*base+s[i];
            }
            res.emplace_back(cur);
        }
        return res;
    };
    vector<vector<u64>> st(n);
    for(int i=0;i<n;i++){
        st[i]=hash(s[i]);
    }
    while(q--){
        string t;
        cin>>t;
        auto cur=hash(t);
        int siz=cur.size();
        int ans=0;
        for(int i=0;i<n;i++){
            int cnt=0;
            for(int j=0;j<siz;j++){
                if(st[i][j]!=cur[j]){
                    for(int k=j*B;k<min((j+1)*B,m);k++){
                        if(s[i][k]!=t[k]){
                            cnt++;
                        }
                    }
                    if(cnt>k){
                        break;
                    }
                }
            }
            if(cnt<=k){
                ans++;
            }
        }
        cout<<ans<<'\n';
    }
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int t=1;
    // cin>>t; 
    while(t--){
        solve();
    }
    return 0;
}



详细

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3624kb

input:

8 6 7 3
delphis
aduncus
peronii
plumbea
clymene
hectori
griseus
electra
delphis
helpiii
perphii
clumeee
eleelea
ddlpcus

output:

1
1
2
2
1
2

result:

ok 6 numbers

Test #3:

score: -100
Time Limit Exceeded

input:

300 300 9 10
dmzampmxe
bteaudaxb
fjfwhhsfq
btnfzqtyp
ijjrkbyht
hkizlvgdc
ukwsnhiff
hacsdrwyl
fbjabnhst
ktsxbgbtg
jopdbsdsr
yxdxxjltd
daechsouq
klrglgwbn
llzhqzlor
ckdedutfn
lkjxcryoe
zvusjevtz
cevrcdltg
tdmmvvpkj
davfsweem
spcfhcitm
aohsfqrqh
lblehevpj
soaqryimp
tbxlulxmn
tnlzbkhda
ukfhjykuk
eghpuua...

output:


result: