PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000084. Phá tường theo bốn hướng (Cross Explosion)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phá tường theo bốn hướng (Cross Explosion)
Cross Explosion
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Consider an by grid with rows numbered from top to bottom and columns from left to right. Initially, every cell contains exactly one wall.
There are bomb placements, processed in the given order. When a bomb is placed at :
- If this cell still contains a wall, destroy this wall only.
- Otherwise, destroy the closest remaining wall in each of the four cardinal directions, looking along the same row or column. A direction with no remaining wall destroys nothing.
When the bomb lands in an empty cell, the four targets are determined simultaneously using the grid state immediately before the explosion. Determine the number of remaining walls after all queries.
Input
The first line contains . Each of the next lines contains .
Output
Print the number of walls remaining.
Subtasks
- Subtask 1 (20 points): , , , , .
- Subtask 2 (30 points): , , , , .
- Subtask 3 (50 points): , , , , .
Example
Input
2 4 3
1 2
1 2
1 3
Output
2
Explanation
The first bomb removes . The second removes , and . The last bomb removes and . Two walls remain.