Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ld long double
- #define ll long long
- const int MAXN = 239300;
- ll INF = 9223372036854775000;
- ll MD = 1000000009;
- ll L = 53;
- ll MAXSIZE = 2000005;
- vector<ll>st(MAXSIZE,0);
- vector<ll> createHash(string s)
- {
- vector<ll>h(s.size()+1,0);
- for(int i=0; i<s.size(); ++i)
- {
- h[i+1] = (h[i]*L +s[i])%MD;
- }
- return h;
- }
- ll getHash(vector<ll>&h,ll l,ll r)
- {
- return (h[r] - h[l-1]*st[r-l+1] +MD*MD)%MD;
- }
- int main()
- {
- ifstream file("data.txt");
- ll N,M,S1,S2,LS;
- file>>N;
- string s1,s2;
- file>>s2;
- s1 = s2;
- reverse(s2.begin(),s2.end());
- st[0] = 1;
- for(int i=1; i<MAXSIZE; ++i)
- {
- st[i] = (st[i-1]*L)%MD;
- }
- //cout<<s1<<" "<<s2<<endl;
- vector<ll>h1 = createHash(s1);
- vector<ll>h2 = createHash(s2);
- int c = 0;
- int maxP = 1;
- for(int i=1; i<=s1.size(); ++i)
- {
- int l,r,m;
- l = i ;
- r = s1.size()+1;
- while(l+1<r){
- m = (l+r)/2;
- cout<<i<<" "<<m<<" "<<s1.size() - m+1<<" "<< s1.size() - i+1<<" "<<(getHash(h1,i,m) == getHash(h2,s1.size() - m+1, s1.size() - i+1))<<endl;
- if(getHash(h1,i,m) == getHash(h2,s1.size() - m+1, s1.size() - i+1)){
- l = m ;
- }else{
- r = m;
- }
- };
- cout<<-i+l+1<<endl;
- maxP = max(maxP,-i+l+1);
- }
- cout<<maxP;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement