Destroy Cells Lunchtine August 2019

Problem :
In it for each K Firstly, I saw whether or not it is visited
Then apply condition for i <= n && j <= m
and change i and j accordingly
According to me each loop will take O((m*n)/(k+1))
Can somebody find the reason for TLE
Thanks in advance :slight_smile:

Convert all integer variable to long long int

@karangreat234 will help u.


Firstly, there is no need for that as at max k = 10^6 which is in range
Secondly, I tried it :sweat_smile:

I think its because u are initialising the visited array each time .
Just initialise it one time and mark it unvisited in the loop after counting.

1 Like