What is test 1? I have even tried out.println('ArozaupalanalapuazorA'); but no luck. Yeah, found, the test 1 is something like this, abcabadkl a palindrome inside the string. const ma=1000; type strin=array[1..ma] of char; zx=record a,x,y:integer; end; var a:strin; i,j,c,k:integer; max:zx; function check(i,j:integer):boolean; var asd,q:integer; label poz; begin asd:=j-i; for q:=i to i+((j-i) div 2) do begin if a[q]<>a[j-(q-i)] then begin check:=false; goto poz; end; end; check:=true; poz: end; begin {assign(Input,'input.txt'); assign(output,'output.txt'); reset(Input); rewrite(Output);} i:=0; while not eoln do begin inc(i); read(a[i]); end; k:=i; c:=i-j; for i:=k downto 2 do for j:=i downto 1 do begin if (check(j,i)) and ((i-j)>=max.a) then begin max.a:=i-j; max.x:=j; max.y:=i; end; end; for i:=max.x to max.y do write(a[i]); writeln; { close(Input); close(Output);} end. 1 answer 1 123 answer 1 good luck!!!11 Thank you, u a very help me. I thought that for 123 1 is incorrect answer) I use DP to find the max substring of the input and its reverse, but I keep getting WA 11... Did anyone else got WA 11? If so, how did you fix it? Thanks in advance :) Hi, check up if you have a string like 'asa ceva nu se mai poate aca' you will get 'asa' as answer. Thanks a lot!!! Your test was perfect for my mistake :) Is there something special in test #23? I got crash (access violation). I have WA in this test. It's my code: #include <iostream> #include <string> #include <algorithm> #define N 1111 using namespace std; string s; int n,d1[N],d2[N],k; int main(){ getline(cin,s); n=s.length(); for (int i=0;i<n;i++){ for (k=1;i-k>=0 && i+k<n;k++) if (s[i-k]!=s[i+k]) break; d1[i]=max(k-1,-1); } for (int i=1;i<n;i++){ if (s[i]!=s[i-1]){ d2[i]=-1; continue; } for (k=1;i-k-1>=0 && i+k<n;k++) if (s[i-k-1]!=s[i+k]) break; d2[i]=max(k-1,0); } int *k1=max_element(d1,d1+n),*k2=max_element(d2+1,d2+n); if (*k1>=*k2+1) for (int i=k1-d1-*k1;i<=k1-d1+*k1;i++) cout<<s[i]; else for (int i=k2-d2-*k2-1;i<=k2-d2+*k2;i++) cout<<s[i]; return 0; } Can I get this test? a you must output a Locally my program prints a. But have AC only if I add if (n==1){ cout<<s<<endl; return 0; } I found my mistake, but I don't know, why there are different answers on my computer and here. F[i]: the longest Palindrom ended at St[i] Cont[i]: the number of continue same characters with St[i], ended at St[i] if St[i] = St[i - F[i - 1] - 1] then F[i] = F[i - 1] + 2 else if St[i] = St[i - 1] then F[i] = Cont[i]; The result is Max(F) What's wrong with it ??? aabbbaabbb it is wrong algorithm The only O(n) Algotithm is suffix tree+LCA or Suffix array + +-1RMQ+LCA+Catersian Tree F[i]: the longest Palindrom ended at St[i] Cont[i]: the number of continue same characters with St[i], ended at St[i] if St[i] = St[i - F[i - 1] - 1] then F[i] = F[i - 1] + 2 else if St[i] = St[i - 1] then F[i] = Cont[i]; The result is Max(F) What's wrong with it ??? That's wrong! There's another O(n) algorithm. It's called Manacher's algorithm. Edited by author 09.10.2011 02:10 I solve this problem using Manacher's algorithm but I got 0.015 ms. For those people who solve this problem using a faster algorithm please tell me the name of the alg..... Used Manacher's algo too, got 0.05 on Java. It is the fastest algo O(n). Here's my code that runs well on my PC. #include<iostream> #include<algorithm> using namespace std; main() { string txt; string txtRev; string tmp; int i; int com; while(cin>>txt){ i=0; do{ for (int n=i+2;n<txt.length();n++){ tmp=txt.substr(i,n); txtRev=tmp; reverse(txtRev.begin(),txtRev.end()); com= txtRev.compare(tmp); if (com==0) break; } i++; }while (com!=0); cout<< tmp <<" " <<endl; } } what is the 19test? sorry,my question if'what is the 12test?' now,what is then 18'th test. try to use more than one prime modulo, if you using them at all zzzdzaadzzz answer is zzz but not zdz I get wrong three times becase of this data.. may it can help you Please add test aa I know AC solution that answers to this test 'a'. why right answer 'a' and not 'aa'? my code can pass all my tests : aaabbbaaa : aaabbbaaa qwerSOMETEXTrewq : ETE bfbaaaafbf : bfb asdaaaafgh : aaa why i get WA on second test? IMHO, right answers for your tests are: bfbaaaafbf : aaaa asdaaaafgh : aaaa Why not? ;) Task on russian say "читающаяся одинаково в обоих направлениях" But if i use toLower(), i have WA, without i have AC In english version we have only "The longest substring with mentioned property". even O(n^3) can pass it....... so just enumerate it....... I know AC solition that have TLE on the following tests: 'b', then 'a' 999 times 'a' 999 times, then 'b' I added your tests, thank you. I know AC solition that have TLE on the following tests: 'b', then 'a' 999 times 'a' 999 times, then 'b' The problem says :"the input contains a single LINE". LINE is assumed to end with '\n' symbol,and I got TLE writing cin.get(c); while(c!='\n') {...cin.get(c);} then I changed this to while(cin>>c) and got AC,but this kind of input ends with EOF character,NOT with '\n'! Admins,please fix this! Where have you read that "LINE is assumed to end with '\n' symbol"??? Is in written in Wikipedia or any other respectable resource? Line is just a set of symbols in the input file, so all stuff for this problem is correct. OK. Now all tests contain lines ending with '\n'. Actually a LINE is not supposed to end with '\n'. What the term "Single LINE" really implies is that there are no printable characters AFTER '\n' symbol IF the latter exists. It's ma prog and it works well, But I get WA at test 2...WHY??? Uses Math; Var x,y:array[1..1000] of char; T:array[0..1000,0..1000] of integer; i,j,n,z,d:integer; BEGIN n:=1; read(x[n]); while (not Eoln) do begin inc(n); read(x[n]); end; for i:=0 to n do T[0,i]:=0; for i:=0 to n do T[i,0]:=0; FOR i:=1 to n do FOR j:=1 to n do if ord(x[i])=ord(x[n-j+1]) then T[i,j]:=T[i-1,j-1]+1 else T[i,j]:=max(T[i-1,j],T[i,j-1]); d:=T[n,n]; i:=n; j:=n; z:=1; while (d<>0) do begin while (T[i-1,j]=d) do DEC(i); while (T[i,j-1]=d) do DEC(j); y[z]:=x[i]; INC(z); DEC(i); DEC(j); DEC(d); end; for i:=z-1 downto 1 do write(y[i]); END. Edited by author 04.12.2008 01:13 I think the answer in the current example must be : aplehtobeaeheaebothelpa NOT : ArozaupalanalapuazorA Plz look at this moment carefully !!! Edited by author 30.11.2008 16:47 #include "iostream" #include "string" #include "vector" using namespace std; bool is_palindrom (string s,int nach,int krai) { for (int i=nach,j=krai;i<=j;i++,j--) if (s[i]!=s[j]) return false; return true; } int main () { char ch; string s,s1,spal; int j=-1,mx=-1; while (cin>>ch) { s+=ch; j++; int i=-1; string s1=s; vector<int>a; do { i++; if (s1[i]==ch) a.push_back(i); } while (i<=s1.length()); for (int i=0;i<a.size();i++) if (is_palindrom(s1,a[i],j)) { string s2=s1.substr(a[i],j-a[i]+1); int l=s2.length(); if (l>mx) {mx=l;spal=s2;break;} } } cout<<spal<<endl; system ("pause"); return 0; } Why're u doing this? Stop posting your own solutions! Admins will add you to ban list (see rules of behavior for this web-site)... And try to solve something interesting and really hard... Edited by author 10.08.2008 00:26 who can give your code to me ? if you used suffix arry or suffix tree The best used c language email: k13795263@126.com |
|