Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <cstring>
- typedef long long LL;
- #define L int(1e6 + 5)
- #define P LL(1e9 + 7)
- using namespace std;
- char s[L];
- LL hash[L], a[L], p[L];
- int t, k;
- LL count_hash(int l, int r) {
- if (!l) return hash[r];
- return hash[r] - hash[l - 1] * p[r - l + 1];
- }
- int main() {
- freopen("autoreg.in", "r", stdin);
- freopen("autoreg.out", "w", stdout);
- gets(s);
- int l = strlen(s);
- scanf("%d", &k);
- hash[0] = s[0];
- for (int i = 1; i < l; i++)
- hash[i] = hash[i - 1] * P + s[i];
- p[0] = 1;
- for (int i = 1; i < l; i++)
- p[i] = p[i - 1] * P;
- for (int i = k - 1; i < l; i++) {
- a[t++] = count_hash(i - k + 1, i);
- }
- sort(a, a + t);
- for (int i = 1; i < t; i++)
- if (a[i] == a[i - 1]) {
- puts("YES");
- return 0;
- }
- puts("NO");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement