QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#713637 | #8334. Gene | StoneXie# | RE | 1ms | 3608kb | C++17 | 2.5kb | 2024-11-05 20:08:26 | 2024-11-05 20:08:26 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define unmap unordered_map
#define unset unordered_set
#define MAXQ priority_queue
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define frep(i,a,b) for(int i=a;i<(b);++i)
using namespace std;
template<typename T> using MINQ=priority_queue<T,vector<T>,greater<T> >;
using pii=pair<int,int>;
using vi=vector<int>;
using vii=vector<vi>;
const int N=105;
int n,q,m,k;
const int M=1e9+7,BASE=233;
int p[60005];
vector<int> gethash(string &s) {
vector<int> res;
int tmp=0;
for(auto c:s) {
tmp=(tmp*BASE+c-'a'+1)%M;
res.push_back(tmp);
}
return res;
}
int check(const vector<int> &h1,const vector<int> &h2) {
auto cal=[&](int l,int r,int idx) ->int{
if(idx==1) {
if(l==0) return h1[r];
else return ((h1[r]-h1[l-1]*p[r-l+1])%M+M)%M;
}
else {
if(l==0) return h2[r];
else return ((h2[r]-h2[l-1]*p[r-l+1])%M+M)%M;
}
};
int now=0;
// cout<<cal(0,1,1)<<" "<<cal(0,1,2)<<endl;
// cout<<cal(2,3,1)<<" "<<cal(2,3,2)<<endl;
for(int i=1;i<=k && now<m;i++) {
// cout<<i<<" "<<now<<endl;
int l=now,r=m-1;
int ans=-1;
while(l<=r) {
int mid= ((l+r)>>1);
if(cal(now,mid,1)==cal(now,mid,2)) {
l=mid+1;
} else {
ans=mid;
r=mid-1;
}
}
if(ans==-1) return 1;
now=ans+1;
}
if(now>=m || cal(now,m-1,1)==cal(now,m-1,2)) return 1;
return 0;
}
vector<int> code[N];
void solve(){
cin>>n>>q>>m>>k;
p[0]=1;
for(int i=1;i<=m;i++) p[i]=p[i-1]*BASE%M;
for(int i=1;i<=n;i++) {
string s;
cin>>s;
code[i]=gethash(s);
// for(auto x:code[i]) cout<<x<<" ";
// cout<<endl;
}
while(q--) {
string t;
cin>>t;
auto codet=gethash(t);
int ans=0;
for(int i=1;i<=n;i++) {
int tmp=check(code[i],codet);
ans+=tmp;
// cout<<tmp<<endl;
// cout<<"***\n";
}
cout<<ans<<endl;
}
}
signed main(){
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
int _t=1;
// cin>>_t;
// cout<<fixed<<setprecision(20);
for(int i=1;i<=_t;i++){
//cout<<"Case "<<i<<": ";
solve();
}
return 0;
}
/*
1 1 4 1
tepu
teri
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
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: 3604kb
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
Runtime Error
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...