ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1297. Palindrome

I got crash in test #23
Posted by anhpnt 21 Sep 2009 23:09
Is there something special in test #23? I got crash (access violation).
Re: I got crash in test #23
Posted by Tranvick 5 Dec 2011 15:07
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?
Re: I got crash in test #23
Posted by zhqc 7 Dec 2011 17:30
a

you must output
a
Re: I got crash in test #23
Posted by Tranvick 8 Dec 2011 20:16
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.