QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#683745 | #8334. Gene | ONISINO | WA | 0ms | 3632kb | C++20 | 3.5kb | 2024-10-27 23:14:51 | 2024-10-27 23:14:51 |
Judging History
answer
#include <bits/stdc++.h>
//DEBUG: https://github.com/sharkdp/dbg-macro
#ifdef LOCAL
#include "../dbg-macro-0.5.1/dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
#define endl '\n'
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double llf;
const ll MAXN=2e5+10,MOD=998244353,INF=1e9;
ll qpow(ll base,ll exp){ll ans=1;while(exp){if(exp&1)(ans*=base)%=MOD;(base*=base)%=MOD;exp>>=1;}return ans;}
ull uqpow(ull base,ull exp){ull ans=1;while(exp){if(exp&1)ans*=base;base*=base;exp>>=1;}return ans;}
template<class T>ll max_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r+1)/2;if(cmp^!check(m))l=m;else r=m-1;}return l;}
template<class T>ll min_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r)/2;if(cmp^!check(m))r=m;else l=m+1;}return r;}
ll exgcd(ll a,ll b,ll &x,ll &y){ll tmp;return b==0?(x=1,y=0,a):(tmp=exgcd(b,a%b,y,x),y-=(a/b)*x,tmp);}
ll highbit(ll x){for(ll i=1;i<(ll)sizeof(ll)*4;i<<=1)x|=x>>i;return x-(x>>1);}
ll lowbit(ll x){return x&(-x);}
//--------Global declared area--------
int n,q,m,k;
ull k1=100,k2=100;
vector<string> s;
vector<vector<pair<ull,ull>>> ha;
void init(){
for(int i=0;i<n;i++){
for(int j=1;j<=m;j++){
ha[i][j].first=((ha[i][j-1].first*k1)+(int)(s[i][j-1]-'a'));
ha[i][j].second=((ha[i][j-1].second*k2)+(int)(s[i][j-1]-'a'));
}
}
}
bool check(int x,string t,vector<pair<ull,ull>> &tha){
ll l=1,mid,cnt=k;
while(cnt>=0){
ll r=m;
// cout<<l<<" "<<r<<" -- "<<endl;
//
// for(int i=1;i<=m;i++){
// cout<<tha[i].first-tha[i-1].first*k1<<','<<tha[i].second-tha[i-1].second*k2<<" ";
// }cout<<endl;
// for(int i=1;i<=m;i++){
// cout<<ha[x][i].first-ha[x][i-1].first*k1<<','<<ha[x][i].second-ha[x][i-1].second*k2<<" ";
// }cout<<endl;
while(l<r){
mid=(l+r)/2;
// cout<<tha[mid].first-tha[l-1].first*uqpow(k1,mid-l+1)<<","<<ha[x][mid].first-ha[x][l-1].first*uqpow(k1,mid-l+1)<<" ";
// cout<<tha[mid].second-tha[l-1].second*uqpow(k2,mid-l+1)<<","<<ha[x][mid].second-ha[x][l-1].second*uqpow(k2,mid-l+1)<<" ";
if(
tha[mid].first-tha[l-1].first*uqpow(k1,(ull)(mid-l+1))==ha[x][mid].first-ha[x][l-1].first*uqpow(k1,(ull)(mid-l+1))
&&tha[mid].second-tha[l-1].second*uqpow(k2,(ull)(mid-l+1))==ha[x][mid].second-ha[x][l-1].second*uqpow(k2,(ull)(mid-l+1))
){
l=mid+1;
// cerr<<"l ";
}else{
r=mid;
// cerr<<"r ";
}
// cerr<<endl;
}
// cerr<<l<<" "<<r<<endl;
if(l<=m&&t[l-1]!=s[x][l-1]){
cnt--;
}
l+=1;
if(l>m){
// cerr<<"good"<<endl;
return true;
}
}
// cerr<<"bad"<<endl;
return false;
}
//--------Global declared end --------
void solve(int test_num){
cin>>n>>q>>m>>k;
s.resize(n);
ha.resize(n,vector<pair<ull,ull>>(m+1,{0,0}));
for(int i=0;i<n;i++){
cin>>s[i];
}
init();
while(q--){
int ans=0;
string t;
cin>>t;
vector<pair<ull,ull>> tha(m+1);
for(int i=1;i<=m;i++){
tha[i].first=((tha[i-1].first*k1)+(int)(t[i-1]-'a'));
tha[i].second=((tha[i-1].second*k2)+(int)(t[i-1]-'a'));
}
for(int i=0;i<n;i++){
ans+=check(i,t,tha);
}
// cout<<"------------------------------";
cout<<ans<<endl;
}
// for(int i=0;i<n;i++){
// cout<<s[i]<<": ";
// for(int j=0;j<=m;j++){
// cout<<":"<<ha[i][j].first<<','<<ha[i][j].second<<" ";
// }
// cout<<endl;
// }
}
int main(){
//std::ios::sync_with_stdio(false);
//std::cin.tie(nullptr),std::cout.tie(nullptr);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++){
solve(i);
//cout.flush();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3632kb
input:
6 4 4 1 kaki kika manu nana tepu tero kaka mana teri anan
output:
2 2 2 0
result:
wrong answer 3rd numbers differ - expected: '1', found: '2'