SHOW:
|
|
- or go back to the newest paste.
1 | #include<bits/stdc++.h> | |
2 | using namespace std; | |
3 | ||
4 | struct HashString | |
5 | { | |
6 | const int BASE = 1e9 + 7; | |
7 | const int P = 127; | |
8 | ||
9 | string s; | |
10 | size_t n; | |
11 | ||
12 | vector<int> power; | |
13 | vector<int> phash; | |
14 | ||
15 | HashString(string ps): s(ps), n(ps.size()) { init(); } | |
16 | ||
17 | void init() | |
18 | { | |
19 | phash.assign(n + 1, 0); | |
20 | power.assign(n + 1, 1); | |
21 | for(size_t i=1; i<=n; ++i) | |
22 | { | |
23 | phash[i] = (1LL * phash[i-1] * P + s[i-1]) % BASE; | |
24 | power[i] = (1LL * power[i-1] * P) % BASE; | |
25 | } | |
26 | } | |
27 | ||
28 | /** hash, power */ | |
29 | inline pair<int, size_t> sub_hash(int i, int j) | |
30 | { | |
31 | return { phash[j+1] - phash[i], j - i }; | |
32 | } | |
33 | }; | |
34 | ||
35 | bool isPrime(int x) | |
36 | { | |
37 | int p=2; | |
38 | while(p * p <= x && x % p != 0) ++p; | |
39 | return ( x > 1 && p * p > x ); | |
40 | } | |
41 | ||
42 | int max_len_preifx(const HashString &s1, const HashString &s2) | |
43 | { | |
44 | int left = 0, right = min(s1.n, s2.n) + 1; | |
45 | while (right - left > 1) | |
46 | { | |
47 | int mid = (left + right) / 2; | |
48 | if ( s1.phash[mid] == s2.phash[mid] ) | |
49 | left = mid; | |
50 | else | |
51 | right = mid; | |
52 | } | |
53 | return left; | |
54 | } | |
55 | ||
56 | int main() | |
57 | { | |
58 | #ifdef AZHUKOV | |
59 | freopen("input.txt", "r", stdin); | |
60 | #endif // AZHUKOV | |
61 | ||
62 | string s; | |
63 | cin >> s; | |
64 | HashString s1(s); | |
65 | reverse(s.begin(), s.end()); | |
66 | HashString s2(s); | |
67 | int n = s1.n; | |
68 | ||
69 | int ans = 0; | |
70 | for(int i=1; i<n-1; ++i) | |
71 | { | |
72 | /** чётная длина */ | |
73 | int h1, h2, p1, p2; | |
74 | tie(h1, p1) = s2.sub_hash(n-1-i+1, n-1); | |
75 | tie(h2, p2) = s1.sub_hash(i, n-1); | |
76 | ||
77 | ||
78 | ||
79 | } | |
80 | } | |
81 |