Help me in solving PASSALL

Problem statement

For above problem statement, I applied logic if there present ‘1’ surrounded by 0’s then no else yes. But I realized, this logic failed on test cases like when there is chain of 1’s surrounded by 0’s.

I’ll delighted if somebody can help me in implementation or have better solution.

Here, my code
Solution: 98962713 - CodeChef