QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#719071 | #8334. Gene | Tomgao4116 | WA | 4ms | 50932kb | C++20 | 2.2kb | 2024-11-06 22:18:56 | 2024-11-06 22:18:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
char s[305][60005];
char t[305][60005];
ull hs[305][60005];
ull ht[305][60005];
ull pi[1000006];
const ll p=13331;
ull gethash1(ll l,ll r,ll idx){
return ht[idx][r]-ht[idx][l-1]*pi[r-l+1];
}
ull gethash2(ll l,ll r,ll idx){
return hs[idx][r]-hs[idx][l-1]*pi[r-l+1];
}
int main(){
ll n,q,m,k;
cin>>n>>q>>m>>k;
pi[0]=1;
for(int i=1;i<=1e6;i++)pi[i]=pi[i-1]*p;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>s[i][j];
hs[i][j]=hs[i][j-1]*p+s[i][j];
}
}
for(int i=1;i<=q;i++){
for(int j=1;j<=m;j++){
cin>>t[i][j];
ht[i][j]=ht[i][j-1]*p+t[i][j];
}
}
for(int i=1;i<=n;i++)s[i][m+1]='a';
for(int i=1;i<=q;i++)t[i][m+1]='b';
for(int i=1;i<=n;i++){
hs[i][m+1]=hs[i][m]*p+s[i][m+1];
}
for(int i=1;i<=q;i++){
ht[i][m+1]=ht[i][m]*p+t[i][m+1];
}
for(int i=1;i<=q;i++){
ll cnt=0;
//对每个ti串:二分检查每个si串与他失配多少个:最多k个:
for(int j=1;j<=n;j++){
//初始位置是1:
ll last=1;
for(int x=1;x<=k;x++){
//last所对第一个匹配位置不同直接看下一个:
if(s[j][last]!=t[i][last]){
last++;
continue;
}
//保证在last位置的s和t串的字母相同:
ll l=last,r=m;
//如果last位置相同:找到下一个最小的失配点:
while(l<r){
ll mid=(l+r)/2ll;
// cout<<"test: "<<" i: "<<i<<" "<<j<<" last: "<<last<<" "<<mid<<" "<<" l r: "<<l<<" "<<r<<" "<<endl;
if(gethash1(last,mid,i)!=gethash2(last,mid,j)){
r=mid;
}else{
l=mid+1;
}
}
last=l+1;
//如果失配点是M+1直接退出:----已经满足条件OK
if(last==m+1)break;
// cout<<"x: "<<x<<" "<<l<<endl;
// cout<<"last: "<<last<<endl;
//每次去掉前面已经匹配成功的位置,从后面新的位置开始尝试匹配:
}
//两种情况OK:1:全部位置检查完毕:2:只检查到中间位置,但后面没有失配的位置:
if(last==m+1||(last<m+1&&gethash1(last,m,i)==gethash2(last,m,j))){
// cout<<"+: "<<j<<endl;
cnt++;
}
}
cout<<cnt<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 18620kb
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: 4ms
memory: 15768kb
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
Wrong Answer
time: 4ms
memory: 50932kb
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:
13 24 22 23 26 23 32 23 19 30 17 14 23 21 22 23 23 20 20 24 19 30 13 24 25 28 14 26 23 21 28 27 24 18 24 26 30 23 27 19 24 24 26 26 18 21 20 26 25 24 27 20 21 22 12 25 22 16 20 24 20 27 20 28 32 27 17 30 17 26 14 22 29 28 23 13 20 20 17 25 20 29 19 22 23 25 23 22 22 20 25 20 23 19 25 16 21 24 28 30 ...
result:
wrong answer 1st numbers differ - expected: '300', found: '13'