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 F first
- #define S second
- #define Lnode 2*node+1
- #define Rnode 2*node+2
- #define MID (l+r>>1)
- #define el '\n'
- #define coutf(x) for(auto v:(x)) cout<<v<<' '; cout<<el
- #define coutp(x) for(auto v:(x)) cout<<v.F<<' '<<v.S<<el
- #define cinl(x) for(auto &v:(x)) cin>>v;
- #define all(x) x.begin(),x.end()
- #define ll long long
- #define sz(x) (int)x.size()
- #define pi pair<ll,ll>
- #define pii pair<ll,pair<ll,ll>>
- #define vi vector<ll>
- using ull = unsigned long long;
- vector<ll>lcp(string& s)
- {
- vector<ll>phi(s.size()+1,0);
- int n=s.size();
- for (int i=1,k=0;i<n;i++)
- {
- k=phi[i-1];
- while (k>0&&s[i]!=s[k])k=phi[k-1];
- if (s[i]==s[k])k++;
- phi[i]=k;
- }
- return phi;
- }
- vector<int> z_function(string s) {
- int n=s.size();
- vector<int> z(n);
- int l = 0, r = 0;
- for(int i = 1; i < n; i++) {
- if(i < r) {
- z[i] = min(r - i, z[i - l]);
- }
- while(i + z[i] < n && s[z[i]] == s[i + z[i]]) {
- z[i]++;
- }
- if(i+z[i]>r) {
- l=i;
- r=i+z[i];
- }
- }
- return z;
- }
- void solve()
- {string a,b;
- getline(cin,a);
- getline(cin,b);
- if (a.size()!=b.size())
- {
- cout<<-1<<" "<<-1<<"\n";
- return;
- }
- string s=a;
- reverse(all(s));
- s+="#"+b;
- auto lastj=lcp(s);
- string s2=b+"#"+a;
- auto z=z_function(s2);
- // for (auto it:lastj)cout<<it<<" ";
- // cout<<"\n";
- // for (auto it:s)cout<<it<<" ";
- // cout<<"\n----\n";
- // for (auto it:z)cout<<it<<" ";
- // cout<<"\n";
- // for (auto it:s2)cout<<it<<" ";
- int sz=a.size();
- int n=s.size();
- int st=-1,en=-1;
- for (int i=0;i<sz-1;i++)
- {
- ll p=lastj[2*sz-i-1];
- if (p&&z[sz+i+2]>=sz-i-p-1)st=i,en=sz-p;
- }
- cout<<st<<" "<<en<<'\n';
- }
- int32_t main() {
- #ifndef ONLINE_JUDGE
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int tc=1;
- //cin>>tc;
- for (int i=1;i<=tc;i++){solve();}
- return 0;
- }
Advertisement