UberOA #27
Count L-Shaped Plots
Estimated MediumJudge-ready
Topics (AI-labelled)HashingBits & Math
In a grid of n rows and m columns, cell (i,j) holds a flower if and only if ((i+j×magic) mod mod) mod 2=1, with coordinates starting from 0. Count the L shapes formed by three distinct flower cells: one cell shares a row with the second and a column with the third, and they need not be adjacent. Each set of three cells is counted only once.
This site's standard input/output is stated explicitly.
Input
One line: n m magic mod; 1≤n,m≤1000, 1≤magic,mod≤10⁶.
Output
Output one integer answer.
Example 1
Input:
4 3 2 2
Output:
12
Example 2
Input:
2 2 1 2
Output:
0
Example 3
Input:
3 3 1 3
Output:
0
Example notes
Example 1: rows 2 and 4 each have 3 flowers. Each of the 6 corner cells can pick the other 2 flowers in its row and the other 1 in its column, for 12 groups in total. Example 2: there are only two flowers, which cannot form a triple, so the output is 0. Example 3: the three flowers are at (0,1), (1,0), and (2,2), with only one flower in each row and column, so the output is 0.
Editorial
Loading solution…