Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- #define mp make_pair
- #define pb push_back
- typedef long long ll;
- typedef long double ld;
- using namespace std;
- int l,r,n;
- int d[1000001];
- char s[1000001];
- int main(){
- // cin >> s;
- scanf("%s", s);
- n = strlen(s);
- l = 0;
- r = 0;
- for(int i = 0; i < n; i++){
- if(i <= r){
- d[i] = min(d[l+r-i],r-i+1);
- }
- while(i - d[i] >= 0 &&
- i + d[i] < n &&
- s[i-d[i]] == s[i+d[i]]){
- d[i]++;
- }
- if(r < i + d[i] - 1){
- l = i - d[i] + 1;
- r = i + d[i] - 1;
- }
- }
- for(int i = 0; i < n; i++){
- // cout << d[i]*2 - 1 << " ";
- d[i] = d[i]*2-1;
- printf("%d ", d[i]);
- }
- cout << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment