#P8783. [蓝桥杯 2022 省 B] 统计子矩阵

    ID: 9701 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2022枚举双指针 two-pointer蓝桥杯省赛

[蓝桥杯 2022 省 B] 统计子矩阵

Problem Description

Given an N×MN \times M matrix AA, please count how many submatrices (minimum 1×11 \times 1, maximum N×MN \times M) satisfy that the sum of all numbers in the submatrix does not exceed the given integer KK.

Input Format

The first line contains three integers NN, MM, and KK.

Then there are NN lines, each containing MM integers, representing the matrix AA.

Output Format

Output one integer representing the answer.

3 4 10
1 2 3 4
5 6 7 8
9 10 11 12
19

Hint

[Sample Explanation]

There are 1919 submatrices that satisfy the condition, including:

There are 1010 of size 1×11 \times 1.

There are 33 of size 1×21 \times 2.

There are 22 of size 1×31 \times 3.

There is 11 of size 1×41 \times 4.

There are 33 of size 2×12 \times 1.

[Test Case Scale and Constraints]

For 30%30\% of the testdata, N,M20N, M \leq 20.

For 70%70\% of the testdata, N,M100N, M \leq 100.

For 100%100\% of the testdata, 1N,M5001 \leq N, M \leq 500, 0Aij10000 \leq A_{i j} \leq 1000, 1K2.5×1081 \leq K \leq 2.5\times10^8.

Lanqiao Cup 2022 Provincial Contest B Group, Problem F.

Translated by ChatGPT 5