SPOJ BITMAP WA

I am trying to solve the following problem : http://www.spoj.com/problems/BITMAP/

I have used a multisource BFS approach to solve the problem. But I keep on getting WA. I tried coding from scratch again but did not find the problem.

Here’s my code: http://ideone.com/ffBWcn

The code runs fine on my system on all the test cases that I’ve tried.
Please help me in finding whats wrong.

I think (Although not sure) you should change scanf("%s",str) to scanf(" %s",str)
Your logic is correct…and it is very painful to read a code… So if it doesnt works then trll me i will try debugging it

And it seems you are always updating distances… Do not do that infact once a point gets a distance it is the least distance

Thanks for replying annh1l1ator!

I tried after updating my code but its still giving WA.

ALso, I am not always updating distances. I am checking the color of the nodes before updating. The nodes which have not been processed and are not in the queue are colored white while others are colored black. Before updating I am checking the color of the nodes

e.g. on line 16 I am checking ((x+1<m)&&(color[x+1][y]==1))
So I will push (x+1,y) only if it is not already processed and then I change color to black.

Hi @na1vecoder!

In line 16 the comparison should be, “x+1 < n”, because your x is a bound on the rows!

Your code would give wrong answer on this test code, for the same reason:

1
5 3
000
001
011
001
000

Change the comparison, and it should work fine! :smiley:

1 Like

Hi, I am trying to solve the same problem. Here is my solution http://ideone.com/xQ4FJ8 . Can anybody figure out why it is giving WA?

my code is producing segment fault
link:https://ideone.com/I8ydMV
would be of great help if anyone can point out the mistake.

Hey Thanks! It did solve the problem. I have accepted your answer but can not upvote as I do not have enough reputation. Will upvote it when I am able to. :slight_smile:

1 Like

Thats because you have put semicolon after if,i mean

If(condition)
A;b;c;

Here if is applied only on A

Do this

If(condition)
A,b,c;

And plz try finding such small bugs urself,u could just print and see where u were wrong

I am trying to solve the same problem.
Here is my code-Y712af - Online Java Compiler & Debugging Tool - Ideone.com.
Can anybody figure out why it is giving WA?