PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000072. Xe về tháp (The Tower is Going Home)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Xe về tháp (The Tower is Going Home)
The Tower is Going Home
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A rook starts at in a -by- grid and aims to reach any cell on the top row. Vertical and horizontal blocking spells are given. Minimize the number removed to allow the rook to reach the destination.
Input
Line 1: . Next lines: vertical wall positions . Final lines: for each horizontal spell.
Output
Print the minimum number of spells removed.
Subtasks
- Subtask 1 (20 points): Exactly one dataset; ; ; ; ; ; vertical walls distinct, all horizontal segments pairwise disjoint.
- Subtask 2 (30 points): Exactly one dataset; ; ; ; ; ; vertical walls distinct, all horizontal segments pairwise disjoint.
- Subtask 3 (50 points): Exactly one dataset; ; ; ; ; ; vertical walls distinct, all horizontal segments pairwise disjoint.
Example
Input
1 2
2
1 1 1
1 3 2
Output
1
Explanation
Removing one of the walls suffices; keeping both prevents reaching the top.