PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000084. Cắt lưới thành ba phần (Check if Grid can be Cut into Sections)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cắt lưới thành ba phần (Check if Grid can be Cut into Sections)
Check if Grid can be Cut into Sections
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An grid contains non-overlapping rectangles. Determine whether two parallel horizontal or vertical cuts can divide the grid into three sections, with at least one rectangle in each section and no rectangle split through its interior. Cuts may lie on rectangle boundaries.
Input
The first line contains , followed by lines . This is the stdin/stdout adaptation.
Output
Print YES if two valid cuts exist; otherwise print NO.
Subtasks
- Subtask 1 (20 points): ; ; ; ; rectangles have pairwise disjoint interiors.
- Subtask 2 (30 points): ; ; ; ; rectangles have pairwise disjoint interiors.
- Subtask 3 (50 points): ; ; ; ; rectangles have pairwise disjoint interiors.
Examples
Input
5 4
1 0 5 2
0 2 2 4
3 2 5 3
0 4 4 5
Output
YES
Explanation
Horizontal cuts at and create three non-empty sections. Every rectangle lies entirely inside one section.