PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000236. Đếm hình chữ nhật có tổng chia hết M (Count Submatrices Divisible by M)
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 có tổng chia hết M (Count Submatrices Divisible by M)
Count Submatrices Divisible by M
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer matrix of size and a positive integer , count nonempty axis-aligned subrectangles whose sum is divisible by , including zero and negative multiples. Different boundaries define distinct rectangles.
Input
The first line contains , followed by rows of integers.
Output
Print the number of valid rectangles.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
2 2 3
1 2
3 4
Output
3
Explanation
The three valid rectangles are the cell 3, the top row (sum 3), and the right column (sum 6).
Example 2
Input
1 3 3
-3 1 2
Output
3
Explanation
The valid segments are [-3], [1,2], and the full row (sum zero).