Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Replace <code>’X’</code> with 1, <code>’Y’</code> with -1 and <code>’.’</code> with 0.
You need to find how many submatrices <code>grid[0..x][0..y]</code> have a sum of 0 and at least one <code>’X’</code>.
Use prefix sum to calculate submatrices sum.