PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000234. Đếm hình chữ nhật toàn số 0 (Count All-Zero Rectangles)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm hình chữ nhật toàn số 0 (Count All-Zero Rectangles)
Count All-Zero Rectangles
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an binary matrix, count nonempty axis-aligned subrectangles consisting entirely of zeros. Rectangles with different boundaries are distinct.
Input
The first line contains , followed by rows of space-separated binary integers.
Output
Print the number of all-zero rectangles.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; all cells are zero.
- Subtask 3 (50 points): ; .
Example 1
Input
2 3
0 0 1
0 0 0
Output
12
Explanation
There are five single cells, three horizontal length-two segments, one horizontal length-three segment, two vertical length-two segments and one 2-by-2 rectangle.
Example 2
Input
1 2
1 1
Output
0
Explanation
There is no zero cell.