Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- #include <vector>
- #include <string>
- #include <cstdlib>
- #include <cmath>
- #include <iomanip>
- #include <cstring>
- #include <cassert>
- #include <queue>
- #include <set>
- using namespace std;
- string s;
- const long long MAX = 1e6;
- const long long p = 2017;
- const long long base = 1e9+7;
- vector <int> deg(MAX);
- void degr(vector <int> °){
- deg[0] = 1;
- for (int i = 1;i<s.size();++i){
- deg[i] = deg[i-1]*p;
- }
- }
- void pref(vector <int> t, string s0){
- t[0] = s0[0];
- for (int i = 1;i<s0.size();++i){
- t[i] = (t[i-1]*p+s0[i])%base;
- }
- }
- int get_hash(int l,int R, vector <int> hro){
- if(l==0)
- return hro[R];
- else{
- int res = (hro[R]-(hro[l-1]*deg[abs(R-l+1)])%base);
- if(res<0)
- res += base;
- return res;
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> s;
- int n = s.size();
- string s1 = s;
- reverse(s.begin(),s.end());
- string s2;
- s2 = s;
- s = s1;
- s1 = s2;
- vector <int> h(n);
- vector <int> h1(n);
- degr(deg);
- pref(h,s);
- pref(h1,s1);
- int ans = 0;
- for (int i = 0;i<n-1;++i){
- for (int j = i+1;j<n;++j){
- cout << i << " " << j << " " << get_hash(i,j,h) << " " << get_hash(i,j,h1) << "\n";
- if(get_hash(i,j,h)==get_hash(i,j,h1))
- ans++;
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement