Skip to main content

Posts

Showing posts from October, 2017

Kickstart 2017 Round A Problem A: Square Counting

Abridged problem statement Count Number of ways to select four points in RxC grid such that these four points make  a square. These squares need not be aligned with the axes. Constraints 1 ≤ T ≤ 100. Small dataset R, C < 10 3 Large dataset R,C < 10 9 Print answer modulo 10 9 + 7 Approach   Let us assume  C >= R. First count all the squares that are aligned with the axes:             number of 1x1 squares is (R-1)*(C-1)             number of 2x2 squares is (R-2)*(C-2)             ...             number of RxR squares is (R-R)*(C-R) Now count all the squares not aligned with the axes:           We can see from the above image that a N x N square has N enclosing squares( including the green squares we counted in the...