File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ // JAI BAJARANG BALI
2+
3+ // manitianajay45
4+
5+ // give me some sunshine, give me some rain , give me another chacne to grow up once again....
6+
7+ // sab moh maya hai....
8+
9+ #include < bits/stdc++.h>
10+ using namespace std ;
11+
12+ #define ll long long
13+
14+ #define mod 1000000007
15+
16+
17+ int main (){
18+ string s;
19+ cin>>s;
20+ ll n=s.length ();
21+
22+ ll x=0 ;
23+ ll y=0 ;
24+ vector<ll> zrr (n,0 );
25+ s+=' *' ;
26+ for (ll i=1 ;i<n;i++){
27+ zrr[i]=max (0ll ,min (zrr[i-x],(y-i+1 )));
28+
29+ while (i+zrr[i]<n && s[zrr[i]]==s[i+zrr[i]]){
30+
31+ x=i;
32+ y=i+zrr[i];
33+ zrr[i]++;
34+ }
35+
36+ }
37+ // for(ll i=0;i<n;i++){
38+ // cout<<zrr[i]<<" ";
39+ // }
40+ // cout<<endl;
41+
42+ for (ll i=n-1 ;i>=1 ;i--){
43+ if (i+zrr[i]==n){
44+ cout<<zrr[i]<<" " ;
45+ }
46+ }
47+ cout<<endl;
48+
49+
50+ return 0 ;
51+
52+ }
You can’t perform that action at this time.
0 commit comments