SNCOUP-correct but giving WA

I have tested my code thoroughly but it is still giving me wrong answer . Can anyone tell me what’s wrong with the code or atleast can give my any one test case for which my code fail?

here is the code link.

https://www.codechef.com/viewsolution/13975891

try this testcase
1

5

@@@@@

@@@@@

Replace @ with *.

your code is going out of bounds and giving run-time error after printing output for this testcase

1 Like

Your code fails here-

Input
1
6
.****.
*....*
Output
3
Expected Output
4

Your code works well for the mirror configuration, i.e

Input
1
6
*....*
.****.
Output
4 (correct)

Even after testing my code with every test case I can think of, I still can’t find what’s wrong with it. Codechef claims it’s WA. Can anyone create a test case that gets a WA?

https://www.codechef.com/viewsolution/13977095

@cheesecoffee

Try this input:

1

3

.**

**.

Expected: 3

Output: 2

@abhishek_iiita

I went through your code, and carefully observed and compared the working of your code on various compilers.

Firstly, a complete, error free code has to work correctly on all (atleast online) compilers. If you see that your output is dependent on compiler, then it means that there is something which you left upto the compiler’s interpretation.

What comes under compiler interpretation?

Things like uninitialized variables. Like lets say i wrote the following snippet-

int j;
int arr[25000];
arr[j]=0;

One compiler will give j a default value of 0, and execute the piece of code likewise. Some will assign a random garbage value (like -100273934 10743495 &etc) and give runtime error/exceptional behaviour.

(In my experience, compilers like hackerrank etc. are more ‘tolerable’ to compiler dependent errors than codechef. )

In your code also i came across such instances. One, for instance is-

ll t,m,i,n,r,c,w,j,k=0,p,kk=0;
.
.
.
  rep(j,0,n){//j is not yet initialized if i am correct

(But your second code also has this, so i think the thing which is causing you to get compiler dependent output lies somewhere else.)

So, now, will you try debugging your code with this in mind for practice, or want me to go through your code and spot it for you?

@vijju123

I completely agree with your explanation but here in the snippet
    ll t,m,i,n,r,c,w,j,k=0,p,kk=0;
.
.
.
  rep(j,0,n){

Here in rep(j,0,n) j will be intialized with 0 as per the macro definition. So I don’t think this is causing any trouble.

my code is giving correct output for both cases i.e, 4 . I have also tried the same input when running on ideone and it is giving 4 for both cases b. you can also check it when dry running the code with these inputs but when running through codechef ide ( https://www.codechef.com/ide ) it is giving output as 3 and 4 respectively. May some thing is wrong with their ide.

actually there is problem from codechef’s side because when i am doing processing and assining a character of first input string to other string in my code it is taking as it’s reverse(* in place of .) and (. in place of *) don’t know why( may be some memory allocation or leak issue) . But this problem is only when running on codechef’s server.

you can analyze my both solutions, they have same logic but in one solution i am using string/char for calculating answer and in other solution converting string to int array( of 0 and 1) and then calculating my answer.
first one WA
second one ACCEPT

my both solutions

https://www.codechef.com/viewsolution/13975891

https://www.codechef.com/viewsolution/13976542

Ok, give me time, i will go through your code in detail :slight_smile:

Ya, i missed that definition lol.

But nevertheless, my only intention was to convey that instances like uninitialized variable, or out of index causing undefined behaviour etc. are the reason for error (thats why i said that-

(But your second code also has this, so i think the thing which is causing you to get compiler dependent output lies somewhere else.)

)

1 Like