Show all threads Hide all threads Show all messages Hide all messages | If you get WA on #7/#15/#17 | WagJK | 1297. Palindrome | 15 Dec 2016 16:12 | 2 | If you are using int(s[i]) to get the representation for any alphabet, you may need to enlarge your counting sort table and counting sort iteration limit. I thought 200 was enough for latin alphabets, but actually I tried several times and succeeded at about 1100. I don't even know why... | Test case for Wrong Answer 1 | j.n.j.d.1 | 1297. Palindrome | 23 Oct 2016 15:25 | 1 | Can anyone provide test case for WA#1, please? | Wrong Answer For Test 19 | K P Charith Chowdary | 1297. Palindrome | 12 Sep 2016 20:32 | 5 | I Got a Wrong Answer For Test 19.. Can Anyone tell what the corresponding input .. if known.. #include<stdio.h> #include<string.h> int main() { int **a,i,j; int answer[2],len,n; char str[1001],revstr[1001]; scanf("%s",&str); n=strlen(str); a=(int**)malloc(sizeof(int**)*n); for(i=0;i<n;i++) a[i]=(int*)malloc(sizeof(int)*n); for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=0; strcpy(revstr,str); for(i=0;i<strlen(str);i++) revstr[i]=str[strlen(str)-i-1]; revstr[i]='\0'; answer[0]=0; answer[1]=0; len=0; for(i=0;i<strlen(str);i++) { for(j=0;j<strlen(revstr);j++) { if(str[i]!=revstr[j]) a[i][j]=0; else { if(i==0||j==0) a[i][j]=1; else a[i][j]=1+a[i-1][j-1]; if(a[i][j]>len) { len=a[i][j]; answer[0]=i; answer[1]=j; } } } } for(i=answer[0]-len+1;i<=answer[0];i++) printf("%c",str[i]); return 0; } Edited by author 23.11.2007 01:20 Try this: 'qwerSOMETEXTrewq', goodluck!;-) And what is to be an answer? The right answer is ETE.I use suffix_array to solve this problem.And I got ac . please help me I also use suffix array, I still wa on #7 | If you get a WA for test#15 | Sandu Petrasco | 1297. Palindrome | 17 Jun 2016 15:51 | 3 | Try abasajhdabba the answer should be 'abba' Mine is. I don't know why but I'm getting a TLE. My answer is 'abba'. But I still have a wrong answer in #12. | O(N^2) idea, works fine | Marian Darius | 1297. Palindrome | 3 May 2016 22:00 | 3 | 4686044 16:50:13 21 Dec 2012 Marian Darius 1297. Palindrome C++ Accepted 0.031 108 KB Just try iterating the middle of the palindrome and extend to both ends, until you find two elements that are different. Seriously? Are you really think that you are the first who do it for O(N^2) with the same idea? And it's not the first topic in the forum about this algo. I don't know why but I get a TLE in #15 with the same approach as yours. | WA 25# | wangchong756 | 1297. Palindrome | 19 Jan 2016 17:27 | 1 | WA 25# wangchong756 19 Jan 2016 17:27 I got a wrong answer on 25 but I don't know why. Is there someone could give me some tests? | WA #17 | Butusov Eugene | 1297. Palindrome | 8 Aug 2015 04:36 | 4 | WA #17 Butusov Eugene 27 Sep 2010 19:04 My program read string S from the input and create reverse string R from the source string. Then I search in cycle with prefix function maximum suffix which may be prefix on string S.substr(i, S.length()-i)+R i - the number of the iteration. Then I check if the getting string the palindrome, I remember then offset and length of the string. In the end print maximum substring. Got WA on 17 test. Thanks on the future...:) 1) First of all, you should compute prefix function on string S.substr(i, S.length()-i)+R.substr(0,S.lenght()-i); 2) add '#' between original string and reverse string: because on test "aaa" correct answer is "aaa" while your programm seems to output "aaaaa". P.S I'm not sure my advices wiil help you,so just write here your mail and i'll send you AC code - my idea is the same with yours but i don't check palindroms - prefix fuction makes by itself! Oh, I insert on concatenating between strings (original and reverse) '#' symbol and got AC! This test 'abcdesdfssaaaassss' show my Error with Manaker algorithm. | Who has WA#24 | BinaryMind [RAU] | 1297. Palindrome | 17 Jun 2015 23:57 | 1 | If you're using hash-function, change your prime base, it has helped me. P.S. I tried this numbers below: This bases cause WA: 13, 71, 97, 313, 919, 967, 1009 And on this I got AC: 157, 2539 Edited by author 17.06.2015 23:58 | why it wrong at Test11? | 116040179 | 1297. Palindrome | 27 Dec 2014 23:25 | 2 | #include <stdio.h> #include <string.h> #include <string> #include <algorithm> using namespace std; #define maxn 2000010
int wa[maxn],wb[maxn],wv[maxn],wss[maxn]; int rank[maxn],height[maxn]; int sa[maxn],r[maxn]; char str[maxn]; char temp[maxn];
int cmp(int *r,int a,int b,int l) { return r[a]==r[b]&&r[a+l]==r[b+l]; }
void da(int *r,int *sa,int n,int m) { int i,j,p,*x=wa,*y=wb,*t; for(i=0; i<m; i++) wss[i]=0; for(i=0; i<n; i++) wss[x[i]=r[i]]++; for(i=1; i<m; i++) wss[i]+=wss[i-1]; for(i=n-1; i>=0; i--) sa[--wss[x[i]]]=i; for(p=1,j=1; p<n; j*=2,m=p) { for(p=0,i=n-j; i<n; i++) y[p++]=i; for(i=0; i<n; i++) if(sa[i]>=j) y[p++]=sa[i]-j; for(i=0; i<n; i++) wv[i]=x[y[i]]; for(i=0; i<m; i++) wss[i]=0; for(i=0; i<n; i++) wss[wv[i]]++; for(i=1; i<m; i++) wss[i]+=wss[i-1]; for(i=n-1; i>=0; i--) sa[--wss[wv[i]]]=y[i]; for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1; i<n; i++ ) x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++; } }
void calheight(int *r,int *sa,int n) { int i,j,k=0; for(i=1; i<=n; i++) rank[sa[i]]=i; for(i=0; i<n; height[rank[i++]]=k) for(k?k--:0,j=sa[rank[i]-1]; r[i+k]==r[j+k]; k++); }
int main() { while(scanf("%s",str)!=EOF) { int i; int len1=strlen(str); strcpy(temp,str); reverse(temp,temp+len1); //printf("%s\n",temp); memset(sa,0,sizeof(sa)); memset(r,0,sizeof(r)); memset(rank,0,sizeof(rank)); memset(height,0,sizeof(height)); str[len1]='#'; for(i=len1+1;i<1+len1*2;i++) str[i]=temp[i-len1-1]; str[i]='\0'; for(i=0;str[i]!='\0';i++) r[i]=str[i]; da(r,sa,i+1,256); calheight(r,sa,i); int k=0,n=i,max=-1; for(i = 2; i <= n; ++ i) if((sa[i]<len1)^(sa[i-1]<len1)) if(k<height[i]){ k=height[i]; max=i; } else if(k==height[i]){ // printf("i=%d max=%d\n",sa[i],sa[max]); if(sa[max]>sa[i]) max=i; } i=sa[max]; for(;i<sa[max]+k;i++) printf("%c",str[i]); printf("\n"); } return 0; } try this test case: aabcc output should be:aa my program was also getting WA on test case 11,when i corrected the program for this test case,it got accepted.I hope it helps you.Thank you. Edited by author 27.12.2014 23:33 Edited by author 27.12.2014 23:33 Edited by author 27.12.2014 23:36 | O(N) | sloboz | 1297. Palindrome | 14 Aug 2014 19:04 | 15 | O(N) sloboz 13 Apr 2004 05:57 this can be done very cool in O(N) with Suffix Trees. Try it! Re: O(N) Gheorghe Stefan 15 Apr 2004 05:15 write me to dpdokov@yahoo.com or post you idia here ?!?!?!?!?!?!?!?! Solution O(N^3) with some optimization AC 0.001 Your time is not so good after rejudge. :) Re: O(N) Shadow of Death 17 Oct 2007 23:16 Just O(2N) Use Prefix Function! Re: O(N) Artem Khizha [DNU] 4 Aug 2010 23:00 After all, I solved the problem by DP in O(N), counting the number of palindromes, though it is rather hard. 2 Shadow of Death: I'm very interested in solution with prefix-function, would you be so kind to tell more about it? I'm a newbie in string-algorithms, but hope to learn them better. if you have learned suffix arrays you can use that to solve these problem . it's not difficult O(N) used hash function ;) Re: O(N) Soucup Adrian 27 Jul 2012 19:05 Naive O( N ^ 2 ) = 0.015, 116 kb Re: O(N) lichtgestalt2710 13 Feb 2014 06:41 also this can be solved with Manacher's algorithm in O(N) =) Re: O(N) lichtgestalt2710 13 Feb 2014 06:41 also this can be solved with Manacher's algorithm in O(N) =) | if you have WA #22 | Levan Arabuli [Tbilisi SU] | 1297. Palindrome | 19 Jul 2014 11:59 | 2 | try this test: 11 answer is 11, not 1 And try tests: 122 221 121 :D | Can you give me test data&//В чем дело? Пролетает то на первом, то на втором тестах. Хотя дома проверку проходит. Можете ли дать мне данные для проверки? | Evgeniy_Rus | 1297. Palindrome | 19 May 2014 01:07 | 1 | var a:array[1..1000] of string; S, pol:string; N, i, j, dlina:longint; function Sum(i, j:integer):string; var k:string; var i1:integer; begin k:=''; for i1:= i to j do k:=k+a[i1]; Sum:=k; end; function Sum1(i, j:integer):string; var k:string; var i1:integer; begin k:=''; for i1:= j downto i do k:=k+a[i1]; Sum1:=k; end; begin readln(S); N:=length(S); for i:= 1 to N do a[i]:=copy(lowercase(S), i, 1); dlina:=0; for i:= 1 to N-1 do begin for j:= i+1 to N do if (Sum(i, j)=Sum1(i, j)) and (length(sum(i, j))>dlina) then begin pol:=Sum(i, j); dlina:= length(sum(i, j)); end; end; writeln(pol); end. | 2 ADMINS: Funny mistake in sample (+) | Vedernikoff 'Goryinyich' Sergey (HSE: АОП) | 1297. Palindrome | 10 Mar 2014 23:58 | 1 | 'The sample text that could be READED the same in both orders ArozaupalanalapuazorA' =) | No subject | I.Smirn0ff | 1297. Palindrome | 10 Mar 2014 18:46 | 1 | Edited by author 10.03.2014 19:18 Edited by author 10.03.2014 19:18 | WA#19HELP | qazwsxmn | 1297. Palindrome | 12 Feb 2014 19:31 | 1 | | WA #20 | Sirojiddin Abdukarimov | 1297. Palindrome | 17 Dec 2013 16:02 | 2 | WA #20 Sirojiddin Abdukarimov 9 Apr 2013 16:05 | To Admin - Weak Tests | bayram | 1297. Palindrome | 6 Oct 2013 15:46 | 2 | There are some AC solutions which are actually O(N^3). Here is the test when some of them fail (3.42s): #include <iostream> #include <fstream> using namespace std; int main() { ofstream fout("test.txt");
for (int i = 0; i < 1000; i++) fout << (char)(i%26+'a');
return 0; } What is the example of such AC solution (submit ID or source code)? | Getting WA #7 | paarth | 1297. Palindrome | 26 Jul 2013 12:01 | 5 | I have used manacher'a algorithm and tried all the test cases discussed in these discussions and getting correct solution.... I have used manacher for even and odd palindromes separately and found the longest and if longest comes again... as in the same length..take the smaller start.. but now,... I got WA #7 ...I initially faced some problem in compilation too..please suggest some test case P.S. : m doing while(getline(cin,string)) and also tried while(cin>>string) is something to be done here...please suggest Got AC...small error in code: basically typo :D It's just bruteforce task. if string is like : abcdef you can tranform it like: ^#a#b#c#d#e#f#$ so,even and odd palindromes all is transformed like odd palindromes. | O(n log n) | linjek | 1297. Palindrome | 6 Jul 2013 20:10 | 1 | Для каждого места (буквы + расстояния между ними) будем проверять длину макс подпалиндрома с помощью бин поиска (его длину). Осталось за О(1) проверить является ли эта подстрока палиндромом, что можно сделать с помощью хешей (заранее посчитать хэш для каждого префикса, и высчитывать хэш подстроки в обе стороны и сравнивать) | I am getting WA at #1 | Atindra Das | 1297. Palindrome | 26 Apr 2013 01:44 | 1 | I have tested for almost all test cases intentioned in discussions. what might be the problem ?? ple help code : /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package timusonlinejudge; import java.util.Scanner; /** * * @author dell */ public class N1297 { public String getPal(String s, int i, int j,String result){ while((i>=0)&&(j<=s.length()-1)){ if((""+s.charAt(i)).equalsIgnoreCase(""+s.charAt(j))){ result = s.charAt(i)+result+s.charAt(j); i--;j++; } else{ break; } } return result; } public String longestPal(String s){ // System.out.println("---"); if(s.isEmpty()){ return ""; } String result = s.substring(0,1);
//System.out.println("---"+result); for(int i = 1; i<s.length();i++){ if((""+s.charAt(i-1)).equalsIgnoreCase(""+s.charAt(i))){ String temp = getPal(s,i-1,i,""); //System.out.println(temp); if(temp.length()>result.length()){ result = new String(temp); //System.out.println(temp); } }
String temp = getPal(s,i-1,i+1,""+s.charAt(i)); //System.out.println(temp); if(temp.length()>result.length()){ result = new String(temp); //System.out.println(temp); }
} return result; } public static void main(String[] args) { N1297 main = new N1297(); Scanner sc = new Scanner(System.in);
String input = sc.nextLine(); //System.out.println(input); System.out.println(main.longestPal(input));
// TODO code application logic here }
} |
|
|