Тема: pomogite ,plz, naiti oshibku v kode
Vot zadachka
http://www.olymp.krsu.edu.kg/GeneralPro … ormat=html
Ya ee reshil s pomochu hasha.
U menya WA10.
Vot moi Kod :
#include <cstring>
#include <algorithm>
#include <iostream>
#include <fstream>
using namespace std;
#define ULL __int64
const ULL base = 97;
char s[2000000];
char s1[100001];
int n,l,m;
ULL hashes[2000000];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
gets(s);
scanf("%d %d\n",&n,&l);
ULL hsh= 0;
ULL pw = 1;
for (int i=0;i<l;i++) {
hsh=hsh*(ULL)base+(ULL)(s[i]-31);
if (i!=l-1) pw=pw*(ULL)base;
}
hashes[m++] = hsh;
int len = strlen(s);
for (int i=1;i<len-l+1;i++) {
hsh=hsh-(ULL)(s[i-1]-31)*pw;
hsh=hsh*(ULL)base+(ULL)(s[i+l-1]-31);
hashes[m++] = hsh;
}
sort(hashes,hashes+m);
for (int j=0;j<n;j++) {
for (int i=0;i<l;i++) s1[i]=getchar();
scanf("\n");
ULL hsh=0;
for (int i=0;i<l;i++) hsh=hsh*(ULL)base+(ULL)(s1[i]-31);
if (binary_search(hashes,hashes+m,hsh)) puts("Yes"); else
puts("No");
}
}