Getting TLE on spoj-BITMAP problem

What should I do in code to avoid getting tle in this problem?
Problem: https://www.spoj.com/problems/BITMAP/
Code: https://ideone.com/R9CgVi