1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| #include <bits/stdc++.h> using namespace std; #define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) #define fo(i,j,k) for(int i=(j),end_i=(k);i<=end_i;i++) #define ff(i,j,k) for(int i=(j),end_i=(k);i< end_i;i++) #define fd(i,j,k) for(int i=(j),end_i=(k);i>=end_i;i--) #define DEBUG(x) cerr<<#x<<"="<<x<<endl #define all(x) (x).begin(),(x).end() #define cle(x) memset(x,0,sizeof(x)) #define lowbit(x) ((x)&-(x)) #define VI vector<int> #define ll long long #define ull unsigned ll #define db double #define lb long db #define pb push_back #define mp make_pair #define fi first #define se second template<class T>inline void read(T &x) { x=0; char ch=getchar(); bool f=0; for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch^48); if(f) x=-x; } template<class T,class... V> inline void read(T &a,V&... b){read(a); read(b...);} #define CASET int ___;for(read(___);___--;)
const int N=1e5+5; const ll mod=1004535809; inline ll Add(ll x,ll y){x+=y; return (x<mod)?x:x-mod;} inline ll Dec(ll x,ll y){x-=y; return (x<0)?x+mod:x;} inline ll Mul(ll x,ll y){return x*y%mod;} inline ll Pow(ll x,ll y) { y%=(mod-1);ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1) ans=ans*x%mod; return ans; } const ll base=31; ll sf[N],sg[N],pw[N]; inline ll get_f(int l,int r) { if(l>r) return 0; return Dec(sf[r],sf[l-1]*pw[r-l+1]%mod); } inline ll get_g(int l,int r) { if(l>r) return 0; return Dec(sg[l],sg[r+1]*pw[r-l+1]%mod); } inline bool check_palindrome(int l,int r) { if(l>r) return 1; assert(l<=r); return get_f(l,r)==get_g(l,r); }
pair<int,int> solve(char *s,int n) { pw[0]=1; fo(i,1,n) pw[i]=pw[i-1]*base%mod; fo(i,1,n) sf[i]=Add(sf[i-1]*base%mod,s[i]-'a'); sg[n+1]=0; fd(i,n,1) sg[i]=Add(sg[i+1]*base%mod,s[i]-'a'); fo(i,1,n/2) if(get_f(1,i)==get_f(i+1,i+i)&&check_palindrome(i+i+1,n)) return {i+1,n}; fo(i,1,n/2) if(get_f(1,i)==get_f(n-i+1,n)&&check_palindrome(i+1,n-i)) return {1,i}; fo(i,1,n/2) if(get_f(n-i-i+1,n-i)==get_f(n-i+1,n)&&check_palindrome(1,n-i-i)) return {1,n-i}; return {-1,-1}; }
int main() { char s[N]; scanf("%s",s+1); int n=strlen(s+1); fo(i,1,n/2) if(s[i]!=s[n-i+1]) { auto ans=solve(s+i-1,n-(i-1)*2); if(ans.fi!=-1) ans.fi+=(i-1),ans.se+=(i-1); printf("%d %d\n",ans.fi,ans.se); return 0; } printf("1 1\n"); return 0; }
|