Hi
I think this problem is badly specified, basically I don't know how to handle questions such: does [0,1] overlaps [1,2]? I consider the time the cat is sleeping as a closed interval, as well as the times the sprinklers are pouring water in each cell. Maybe this approach is wrong and I should have considered open intervals.
This is the function I think is the main task:

int overlap (int c, int d, int module) {
/*return 1 if there exist x in [a,b] such that x mod module is in the interval [c,d] (c,d<module), else return 0*/
if (b - a >= module) return 1;
b %= module;
a %= module;
if (a < c)
if (b >= a && b < c) return 0;
else return 1;
else if (a > d)
if (b >= a && b < module || b < c) return 0;
else return 1;
return 1;
}

As in problem statement, time interval for each sprinklers begin at time=0
and if a sprinkler has period p then, according to one-cycle movement, that sprinkler will pour water at it`s first direction for [0,p) and in time p it changes its direction without pouring water!

Coordinaters of sprinklers are given as <row> <column>

But size of the field as <number of columns> <number of rows>

I realize it only after online contest...

...? I can't find your problem.

The first line of each test case contains 3 integers 1<=m,n<=100 (the dimensions of the garden), and 0<=k<=1000 which is the number of sprinklers in it. The next lines each consist of 4 non negative integers r,c,p,R and a character d. 1<=r<=m and 1<=c<=n indicate the coordinates of the i-th sprinkler in row-column format ......

My problem was that I considered m is a number of rows and n number of columns! (row-column format). When I saw here last post by w k I realized that m is a number of columns!

kp wrote:My problem was that I considered m is a number of rows and n number of columns! (row-column format). When I saw here last post by w k I realized that m is a number of columns!

Because my AC code is handled m and n as row-column format,
I think it is your code own problem.
And, I think the last post of "w k" didn't say about such things.
I want to know other solver's opinion too.

kp wrote:My problem was that I considered m is a number of rows and n number of columns! (row-column format). When I saw here last post by w k I realized that m is a number of columns!

Because my AC code is handled m and n as row-column format,
I think it is your code own problem.
And, I think the last post of "w k" didn't say about such things.
I want to know other solver's opinion too.