PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000107. Diện tích hình chữ nhật bao trọn các điểm đen (Smallest Rectangle Enclosing Black Pixels)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Diện tích hình chữ nhật bao trọn các điểm đen (Smallest Rectangle Enclosing Black Pixels)
Smallest Rectangle Enclosing Black Pixels
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an image of 0 (white) and 1 (black) pixels, all black pixels are four-neighbor connected. A known black pixel has zero-based coordinate . Return the area (number of grid cells) of the smallest axis-aligned rectangle that contains every black pixel.
Input
The first line contains . Each of the next lines is a string of exactly characters 0 or 1.
Output
Print one integer, the area of the smallest rectangle containing every black pixel.
Subtasks
- Subtask 1 (20 points): ; , ; each image entry is
0or1, the chosen pixel is black, and all black pixels are four-neighbor connected. - Subtask 2 (30 points): ; , ; each image entry is
0or1, the chosen pixel is black, and all black pixels are four-neighbor connected. - Subtask 3 (50 points): ; , ; each image entry is
0or1, the chosen pixel is black, and all black pixels are four-neighbor connected.
Examples
Input
3 4 0 2
0010
0110
0100
Output
6
Explanation
The black coordinates are . The topmost and bottommost rows are , giving height . The leftmost and rightmost columns are , giving width . The minimal bounding rectangle has area .