DMOPC '18 Contest 2 P6 - Standing Ovation

View as PDF

Submit solution


Points: 30 (partial)
Time limit: 7.0s
Memory limit: 1G

Author:
Problem type

At the Nova Theatre, the balcony seats can be seen as a grid with M rows and N columns. The theatre is packed and the seats are all filled. At the end of the play, K people in the balcony stand to give their applause. The ith of these K people is sitting in row ri, column ci. The rest of the M×N people will only stand if at least two people adjacent to them are standing. How many people will end up standing?

Constraints

KM×N
1riM for all 1iK
1ciN for all 1iK

Subtask 1 [10%]

M=2
1N100000
1K100000

Subtask 2 [30%]

1M,N1000
1K100000

Subtask 3 [10%]

1M,N100000
1K1000

Subtask 4 [50%]

1M,N100000
1K100000

Input Specification

The first line will contain three space-separated integers, M,N,K.
The next K lines each contain two space-separated integers, ri and ci, representing the ith person initially standing.

Sample Input 1

Copy
3 4 5
1 1
1 2
1 3
2 1
3 1

Sample Output 1

Copy
9

Explanation for Sample 1

Initially, the grid appears as:

Copy
S S S O
S O O O
S O O O

where S denotes someone standing and O denotes someone sitting.
Then it becomes:

Copy
S S S O
S S O O
S O O O

Then:

Copy
S S S O
S S S O
S S O O

Finally:

Copy
S S S O
S S S O
S S S O

No more people stand, so the 9 people end up standing.

Sample Input 2

Copy
3 5 4
1 1
3 1
1 4
2 5

Sample Output 2

Copy
7

Sample Input 3

Copy
3 5 4
1 1
3 1
1 3
2 4

Sample Output 3

Copy
12

Comments

There are no comments at the moment.