PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000214. Cạnh hình vuông lớn nhất có tổng không vượt ngưỡng (Maximum Side Length)
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ạnh hình vuông lớn nhất có tổng không vượt ngưỡng (Maximum Side Length)
Maximum Side Length
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An matrix contains nonnegative integers. Find the largest side length of a nonempty square of consecutive cells, with sides parallel to the matrix axes, whose cell sum is at most . Print 0 if no such square exists.
Input
The first line contains three integers . Each of the next lines contains exactly integers .
Output
Print the largest side length, or 0 if no valid square exists.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
3 7 4
1 1 3 2 4 3 2
1 1 3 2 4 3 2
1 1 3 2 4 3 2
Output
2
Explanation
The 2-by-2 square in the first two columns sums to 4. Every 3-by-3 square exceeds 4.
Example 2
Input
5 5 1
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
Output
0
Explanation
Every single cell already exceeds 1.
Example 3
Input
2 3 0
0 0 2
0 0 1
Output
2
Explanation
The leftmost four cells form a square of side 2 with sum 0.