AT_abc461_d.Count Subgrid Sum = K
普及/提高-
通过率:0%
时间限制:4.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an H×W grid, and each cell contains an integer 0 or 1.
The information of the integer written in each cell is given as H strings S1,S2,…,SH of length W. If the j-th character of Si is 0, then 0 is written in the cell at the i-th row from the top and the j-th column from the left of the grid; if the j-th character of Si is 1, then 1 is written in that cell.
Find the number of rectangular regions where the sum of the written integers equals K.
More formally, find the number of quadruples of integers (r1,c1,r2,c2) satisfying all of the following conditions:
- 1≤r1≤r2≤H
- 1≤c1≤c2≤W
- The sum of the integers written in the cell at the i-th row from the top and the j-th column from the left, over all pairs of integers (i,j) satisfying r1≤i≤r2,c1≤j≤c2, equals K.
有一个 H×W 的网格,每个格子中包含一个整数 0 或 1。
每个格子中所写整数的信息由 H 个长度为 W 的字符串 S1,S2,…,SH 给出。若 Si 的第 j 个字符为 0,则网格中从上往下第 i 行、从左往右第 j 列的格子中写有数字 0;若 Si 的第 j 个字符为 1,则该格子中写有数字 1。
求所有满足其中所写整数之和恰好等于 K 的矩形区域的个数。
更准确地说,求满足以下所有条件的四元组整数 (r1,c1,r2,c2) 的个数:
- 1≤r1≤r2≤H
- 1≤c1≤c2≤W
- 对所有满足 r1≤i≤r2 且 c1≤j≤c2 的整数对 (i,j),对应格子(即从上往下第 i 行、从左往右第 j 列)中所写整数的总和等于 K。
输入格式
The input is given from Standard Input in the following format:
H W K
S1
S2
⋮
SH
输入从标准输入中按以下格式给出:
H W K
S1
S2
⋮
SH
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
3 4 3 1001 1101 0110
输出#1
8
输入#2
5 4 20 0101 1010 0101 1010 0101
输出#2
0
输入#3
15 20 17 10111101101100000100 01100000000010000011 01110010111000111000 11001100000111011000 10100001100011100010 01101000101010000101 10110001111110000100 10110011101100101101 01010001110011001001 01010110010001100110 01110100011110011110 01100000100111010010 11001101100111101100 10111100010101111011 00101101011100010000
输出#3
448
说明/提示
Sample 1 Explanation:
There are eight rectangular regions where the sum of the written integers equals K:
- The rectangular region extracted from row 1 to row 2 from the top and column 1 to column 2 from the left
- The rectangular region extracted from row 1 to row 2 from the top and column 1 to column 3 from the left
- The rectangular region extracted from row 1 to row 2 from the top and column 2 to column 4 from the left
- The rectangular region extracted from row 1 to row 3 from the top and column 2 to column 3 from the left
- The rectangular region extracted from row 1 to row 3 from the top and column 3 to column 4 from the left
- The rectangular region extracted from row 2 to row 2 from the top and column 1 to column 4 from the left
- The rectangular region extracted from row 2 to row 3 from the top and column 1 to column 2 from the left
- The rectangular region extracted from row 2 to row 3 from the top and column 2 to column 3 from the left
Constraints
- H and W are integers between 1 and 500, inclusive.
- K is an integer between 0 and HW, inclusive.
- Si is a string of length W consisting of
0and1.
样例 1 解释:
共有八个矩形区域,其中所写整数之和等于 K:
- 从上往下第 1 行到第 2 行、从左往右第 1 列到第 2 列所构成的矩形区域
- 从上往下第 1 行到第 2 行、从左往右第 1 列到第 3 列所构成的矩形区域
- 从上往下第 1 行到第 2 行、从左往右第 2 列到第 4 列所构成的矩形区域
- 从上往下第 1 行到第 3 行、从左往右第 2 列到第 3 列所构成的矩形区域
- 从上往下第 1 行到第 3 行、从左往右第 3 列到第 4 列所构成的矩形区域
- 从上往下第 2 行到第 2 行、从左往右第 1 列到第 4 列所构成的矩形区域
- 从上往下第 2 行到第 3 行、从左往右第 1 列到第 2 列所构成的矩形区域
- 从上往下第 2 行到第 3 行、从左往右第 2 列到第 3 列所构成的矩形区域
约束条件
- H 和 W 是介于 1 到 500(含)之间的整数。
- K 是介于 0 到 HW(含)之间的整数。
- Si 是一个长度为 W 的字符串,仅由字符
0和1组成。
输入解题思路,AI测评打分。不知道怎么写?