PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000134. Cạnh hình vuông lớn nhất có tổng không vượt ngưỡng (Maximum Side Length of a Square with Sum Less than or Equal to Threshold)
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 of a Square with Sum Less than or Equal to Threshold)
Maximum Side Length of a Square with Sum Less than or Equal to Threshold
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given a nonnegative matrix with rows and columns, the sum of a square submatrix is the sum of its contiguous cells. Find the largest integer side length for which at least one square submatrix has sum at most . If even a square cannot qualify, return .
Input
The first line contains . Each of the following lines contains values .
Output
Print one integer: the greatest feasible square side length.
Subtasks
- Subtask 1 (20 points): ; ; , , .
- Subtask 2 (30 points): ; ; , , .
- Subtask 3 (50 points): ; ; , , .
Examples
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 upper-left square consists of four ones, with sum . Any square has sum greater than : each row of three consecutive columns has at least sum , so a full square exceeds the threshold. Thus the maximum side is 2.