SPOJ BITMAP WA

i am trying to solve http://www.spoj.pl/problems/BITMAP/ problem.
my code executes fine in my computer but its giving wrong answer while running on SPOJ .

i can not make out for which testcase it is failing.
I have implemented BFS on every vertex with value 1 by pushing them into queue and then i searched from these points by a bfs in the array to update the ans array

link to my code : http://ideone.com/locW8p

Hello abhinandan,

Here is the link to accepted solution of yours code link

Here are the list of the flaws in your implementation…

  1. Major flaw you were reading each string into a number which you cannot because the values of m can be 182. Reread the constraints properly …

  2. if(x>=0&&x<n&&y>=0&&y<m&&!visited[x][y]) Look at this condition which i have added in your coded…

    if(!visited[x][y]&&x>=0&&x<n&&y>=0&&y<m) which you have written this way in your original code …

suppose x values becomes -1 and if you do visited[-1][y] first then it will surely produce run time error so check for these condition very precisely please …

Please look at your code now i have changed some things which surely help you implementing your logic …

Cheers coding and codechef …

Wishing you a very very happy new year …

Hope you find my words useful to you …

1 Like

you can use string in your code to read the input as i have added in your code

you can also use this to read a single character either
char ch ;
cin >> ch ;

or int num ;
scanf("%1d",&num) ;

// this read only one digit at a time …

Thanks sir…Got AC :slight_smile:
Happy New Year to you too sir…

Oh I just checked … You are also from NIT KKR … great …

One more thing if you find the answer to your problem then please accept it so that other will not waste their precious on this post any more … and the post will be closed …