PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000224. Tổng vùng lân cận của ma trận (Matrix Block Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng vùng lân cận của ma trận (Matrix Block Sum)
Matrix Block Sum
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an matrix and an integer , construct a matrix of the same size. Entry is the sum of original cells within the matrix with and . Clip at the boundary; do not wrap or reuse updated entries.
Input
The first line contains . The next lines each contain integers.
Output
Print rows, each containing space-separated integers of the result matrix.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
3 3 1
1 2 3
4 5 6
7 8 9
Output
12 21 16
27 45 33
24 39 28
Explanation
The top-left cell sums four entries to 12; the center includes all entries.
Example 2
Input
3 3 2
1 2 3
4 5 6
7 8 9
Output
45 45 45
45 45 45
45 45 45
Explanation
Every neighborhood covers the full matrix, giving 45 everywhere.