Wrong Answer , despite getting the right output .

I want to know why it happens with me many a times that my solutions give right output but I still get a WA ?
For example , for this question http://www.codechef.com/DSPF2013/problems/DS7/ . My solution was giving the right output , but a WA .
I can give the link to my solution here , if allowed .

4 Likes

as they say in the mail “… please do not consider the given test cases as the ‘sole’ test cases…”

most of the times it is advisable to have your own test case which is ‘manually’ worked out as a reference. depending on the complexity of the test cases you generate, less is the number you have to generate.

as far as coding is consider, coincidences are pretty common thing wherein you end up ‘seeing’ the ‘correct’ answer rather than actually ‘getting’ the ‘correct’ answer!

@ishitva the line in your code

char msg[200];

should be

 char msg[201];

one more for the ‘\0’ character try changing this i hope u will get AC…

2 Likes

@amitupadhyay is correct, your array size is the culprit.

SPOJ TOANDFRO

*Note: the scanf("%d\n", &t) part in the above code.

PRISON BREAK
http://www.codechef.com/viewsolution/1830845

1 Like

This was my code during the contest.

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
using namespace std;

const int SIZ = 210;

int main() {
    int t;
    scanf("%d", &t);
    char s[SIZ];
    while(t--) {
  	    int l, col, row;
	    scanf("%d\n", &col);
	    for(l=0; l<SIZ; l++) {
		    scanf("%c", &s[l]);
		    if(s[l] == '\n') {
			    l--;
			    break;
		    }
	    }
	    //cout<<"s "<<endl;
	    /*for(int i=0; i<=l; i++)
		    printf("%c", s[i]);
	    cout<<endl;*/
	    row = (l+1) / col;
	    //cout<<"row "<<row<<" col "<<col<<endl;
	    char s2[row][col];
	    char s3[row][col];
	    int k=0;
	    for(int i=0; i<row; i++) {
		   for(int j=0; j<col, k<=l; j++) {
			    s2[i][j] = s[k];
			    k++;
		   }
	    }
	    //cout<<"s2 "<<endl;
	    /*for(int i=0; i<row; i++) {
		    for(int j=0; j<col; j++) {
		    	printf("%c", s2[i][j]);
		    }
		    cout<<endl;
	    }
	    cout<<endl;*/
	    for(int i=0; i<row; i++) {
		    for(int j=0; j<col; j++) {
		    	if(i%2!=0) {
		    		s3[i][j] = s2[i][col-1-j];
			}
			else {
				s3[i][j] = s2[i][j];
			}
		}
	    }
	    //cout<<"s3 "<<endl;
	    for(int i=0; i<col; i++) {
	    	for(int j=0; j<row; j++) {
	    		printf("%c", s3[j][i]);
	    	}
	    	//cout<<endl;
	    }    
	    cout<<endl;
	
    }
    return 0;
}
1 Like

@ishitva please share your solution link.

@upendra1234 http://ideone.com/GHtfgR

@avinrox I tried http://www.spoj.com/problems/TOANDFRO/ I tried my solution at SPOJ after modifying it to receive input until a 0 is entered , but got an AC there. :confused:

@amitupadhyay , Where to submit the solution now ? the submissions have closed. I am unable to find it in the practice section .

@ishitva then you have to wait :frowning: until it comes into practice section

Okay. But my previous solution gave an AC at SPOJ after modifying it to take input until a 0 is entered
http://ideone.com/AX4uT4 for
http://www.spoj.com/problems/TOANDFRO/ ?

@amitupadhyay , I didn’t have to use the extra element there :confused:

SPOJ do not cover all the corner test cases… go to ideone.com input a string of length of 200… and see u will get WA…

talking of SPOJ it also have a FLIPCOIN question as on codechef i did get an AC here but still having WA here on codechef… testing s intense in codechef

1 Like

@amitupadhyay Thanks for you help .

@bugkiller , the codechef solution isn’t public yet .

Try to look for edge cases.