Precompute the number of consecutive 1 below the ( i , j ) in j - th column and the number of consecutive 1 s on right side of ( i , j ) in i - th row .
void precompute ( int mat [ R ] [ C ] , int ryt [ ] [ C + 2 ] , int dwn [ R + 2 ] [ C + 2 ] ) {