Girls '
Time limit:3000/1000 MS (java/others) Memory limit:65535/32768 K (java/others) total submission (s): 1160 Accepted Submission (s): 448
Problem Descriptionone Day, Sailormoon Girls is so delighted this they intend to the about palindromic strings. Operation contains-Steps:first Step:girls would write a long string (only contains lower case) on the paper. For example, "ABCDE", but ' a ' inside was not the real ' a ', so means if we define the ' B ' is the real ' a ' and then we can inf Er that ' C ' are the real ' B ', ' d ' is the real ' C ' ..., ' a ' is the real ' z '. According to this, the string "ABCDE" Changes to "Bcdef". Second Step:girls'll find out the longest palindromic string in the given string, the length of palindromic string must be equal or more than 2.
Inputinput contains multiple cases. Each case contains parts, a character and a string, they is separated by one space, the character representing the RE Al ' A ' is and the length of the string won't exceed 200000.All input must be lowercase. If the length of string is Len, it's marked from 0 to len-1.
Outputplease execute the operation following the steps. If you find one, output the start position and end position of palindromic string in a line, next line output the real pal Indromic string, or output "No solution!". If There is several answers available, please choose the string which first appears.
Sample Inputb Babd a ABCD
Sample Output0 2 Aza No solution!
Puzzle: Save the position with Manacher, and then escape the character;
Code:
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include < Algorithm> #include <vector>using namespace std;const int inf=0x3f3f3f3f; #define MEM (x, y) memset (x,y,sizeof ) typedef long Long ll;const int Maxn=200010;char s[maxn],a[maxn<<1];int ans,ps;int p[maxn<<1];void Manacher () {int m=1,l=1,r=1; Ans=0;ps=0;int Len=strlen (a);p [0]=p[1]=1;for (int i=2;i<len;i++) {if (r>i) p[i]=min ( p[m-(i-m)],r-i); else P[i]=1;while (A[i-p[i]]==a[i+p[i]]) p[i]++; if (p[i]+i>r) r=p[i]+i,m=i;if (P[i]-1>ans) ans=p[i]-1,ps=i;}} int main () {char ch[2];while (~scanf ("%s%s", ch,s)) {int Len=strlen (s); a[0]= ' # '; for (int i=0;i<len;i++) {a[i*2+1]=s[i ];a[i*2+2]= ' # ';} a[len*2+1]= ' # '; a[len*2+2]= ' + '; manacher ();//printf ("%d\n", ans), int l= (ps-ans+1)/2,r=l+ans-1;if (ans==1) {puts ("No Solution! "); Continue;} printf ("%d%d\n", l,r); int t=ch[0]-' a '; for (int i=l;i<=r;i++) {if (s[i]-' a ' >=t) printf ("%c", s[i]-t); else printf (" %c ", s[i]-t+26);} Puts ("");} return 0;}
Girls ' (manacher)