WA in LEBOMBS

[Problem][1]

[My code][2]

Please provide some test cases where my code fails. Thank you.
[1]: http://www.codechef.com/problems/LEBOMBS/
[2]: http://ideone.com/fFy9mT

Here’s a simple one your code fails

1 //No of test case

6 //No of buildings

001100

answer should be 2 , i.e only the first and last buildings stay safe.
While your code gives 3

The reason behind it is a simple fault with this loop

for (i = 1; i < (n-1); ++i)
		{
			if (str[i] == '1')
			{
				str[i] = 'a';
				str[i-1] = 'a';
				str[i+1] = 'a';
			}	
		}

when i=2 it makes the string “0aaa00” and then the loop won’t check for the second bomb and thus the second last building will remain and will be counted as safe building :wink:

Cheers

2 Likes