#K50027. Counting Obstacle Cells in a Grid
Counting Obstacle Cells in a Grid
Counting Obstacle Cells in a Grid
You are given a grid with N rows and M columns. Initially, each cell is empty (0). You will perform K operations. Each operation is given as a triple \((x, y, v)\) that sets the cell in row x
and column y
to value v
. A cell is considered an obstacle if its value is 1. Note that if a cell is updated more than once, the latest operation overrides the previous value.
Your task is to count the number of obstacle cells in the grid after all operations have been performed.
inputFormat
The input is read from stdin
and has the following format:
N M K x1 y1 v1 x2 y2 v2 ... xK yK vK
Where:
N
is the number of rows.M
is the number of columns.K
is the number of operations.- Each of the next
K
lines contains three integers:x
,y
, andv
(wherev
is either 0 or 1).
outputFormat
Output a single integer to stdout
which is the number of obstacle cells (cells with value 1) in the grid after all operations have been applied.
4 5 3
2 3 1
1 4 1
0 0 1
3