CCO Preparation Test 1 - Double Cross

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

After watching Game of Thrones, Bruce decided to make a family symbol. He wants his symbol to be special, so he chooses the double cross as his symbol. The double cross is made by two horizontal and one vertical line segments, which are marked by 1 in a 01 grid. A valid double cross must satisfy the following constraints:

  • The two horizontal line segments cannot be next to each other. There is at least one spare row between the two horizontal line segments.

  • The top of the vertical segment must be higher than both of the horizontal segments, and the bottom of the vertical segment must be lower than both of the horizontal segments.

  • The vertical segment must pass the middle points of the two horizontal segments.

  • The top horizontal segment must be shorter than the bottom horizontal segment.

The following figure illustrates two valid double crosses. The right double cross in the figure is the minimal double cross.

..........
....1.....          ..1..
..11111...          .111.
....1.....          ..1..
111111111.          11111
....1.....          ..1..
....1.....

Given an R \times C grid marked with 0 and 1, please write a program to find the number of valid double crosses in the grid.

Input Specification

The first line of input will consist of two integers, R and C (1 \leq R, C \leq 10\,000 and R \times C \leq 1\,200\,000), the number of rows and the number of columns in the grid, respectively.

The second line of input will consist of one integer, N (0 \leq N \leq 10\,000), which is the number of 0s in the grid.

Each of the next N lines will consist of two integers separated by a space, r and c (1\leq r \leq R, 1 \leq c \leq C), which represents that there is a 0 at (r, c) in the grid.

Output Specification

Output one integer, the number of double crosses in the grid modulo 1\,000\,000\,009 (= 10^9+9).

Sample Input

6 8
12
1 2
1 3
1 4
1 6
2 2
3 2
3 3
3 4
3 7
6 4
6 6
4 8

Sample Output

5

Explanation of Output for Sample Input

The size of the input grid is R=6, C=8. The grid and all the valid double crosses are illustrated in the following figure. There are 5 valid double crosses in total.

10001011    ....1...    ....1...    ....1...    ....1...    ....1...
10111111    ...111..    ...111..    ...111..    ...111..    ..11111.
10001101    ....1...    ....1...    ....1...    ....1...    ....1...
11111110    ..11111.    ..11111.    ....1...    ....1...    ....1...
11111111    ....1...    ....1...    ..11111.    .1111111    .1111111
11101011    ........    ....1...    ....1...    ....1...    ....1...

Comments


  • 0
    FatalEagle  commented on March 5, 2015, 8:45 a.m.

    2 new test cases have been added.