AT_abc461_d.Count Subgrid Sum = K

普及/提高-

通过率:0%

时间限制:4.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is an H×WH \times W grid, and each cell contains an integer 00 or 11.
The information of the integer written in each cell is given as HH strings S1,S2,…,SHS_1, S_2, \dots, S_H of length WW. If the jj-th character of SiS_i is 0, then 00 is written in the cell at the ii-th row from the top and the jj-th column from the left of the grid; if the jj-th character of SiS_i is 1, then 11 is written in that cell.

Find the number of rectangular regions where the sum of the written integers equals KK.
More formally, find the number of quadruples of integers (r1,c1,r2,c2)(r_1, c_1, r_2, c_2) satisfying all of the following conditions:

  • 1≤r1≤r2≤H1 \le r_1 \le r_2 \le H
  • 1≤c1≤c2≤W1 \le c_1 \le c_2 \le W
  • The sum of the integers written in the cell at the ii-th row from the top and the jj-th column from the left, over all pairs of integers (i,j)(i, j) satisfying r1≤i≤r2,c1≤j≤c2r_1 \le i \le r_2, c_1 \le j \le c_2, equals KK.

有一个 H×WH \times W 的网格,每个格子中包含一个整数 00 或 11。
每个格子中所写整数的信息由 HH 个长度为 WW 的字符串 S1,S2,…,SHS_1, S_2, \dots, S_H 给出。若 SiS_i 的第 jj 个字符为 0,则网格中从上往下第 ii 行、从左往右第 jj 列的格子中写有数字 00;若 SiS_i 的第 jj 个字符为 1,则该格子中写有数字 11。

求所有满足其中所写整数之和恰好等于 KK 的矩形区域的个数。
更准确地说,求满足以下所有条件的四元组整数 (r1,c1,r2,c2)(r_1, c_1, r_2, c_2) 的个数:

  • 1≤r1≤r2≤H1 \le r_1 \le r_2 \le H
  • 1≤c1≤c2≤W1 \le c_1 \le c_2 \le W
  • 对所有满足 r1≤i≤r2r_1 \le i \le r_2 且 c1≤j≤c2c_1 \le j \le c_2 的整数对 (i,j)(i, j),对应格子(即从上往下第 ii 行、从左往右第 jj 列)中所写整数的总和等于 KK。

输入格式

The input is given from Standard Input in the following format:

HH WW KK
S1S_1
S2S_2
⋮\vdots
SHS_H

输入从标准输入中按以下格式给出:

HH WW KK
S1S_1
S2S_2
⋮\vdots
SHS_H

输出格式

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 KK:

  • The rectangular region extracted from row 11 to row 22 from the top and column 11 to column 22 from the left
  • The rectangular region extracted from row 11 to row 22 from the top and column 11 to column 33 from the left
  • The rectangular region extracted from row 11 to row 22 from the top and column 22 to column 44 from the left
  • The rectangular region extracted from row 11 to row 33 from the top and column 22 to column 33 from the left
  • The rectangular region extracted from row 11 to row 33 from the top and column 33 to column 44 from the left
  • The rectangular region extracted from row 22 to row 22 from the top and column 11 to column 44 from the left
  • The rectangular region extracted from row 22 to row 33 from the top and column 11 to column 22 from the left
  • The rectangular region extracted from row 22 to row 33 from the top and column 22 to column 33 from the left

Constraints

  • HH and WW are integers between 11 and 500500, inclusive.
  • KK is an integer between 00 and HWHW, inclusive.
  • SiS_i is a string of length WW consisting of 0 and 1.

样例 1 解释:
共有八个矩形区域,其中所写整数之和等于 KK:

  • 从上往下第 11 行到第 22 行、从左往右第 11 列到第 22 列所构成的矩形区域
  • 从上往下第 11 行到第 22 行、从左往右第 11 列到第 33 列所构成的矩形区域
  • 从上往下第 11 行到第 22 行、从左往右第 22 列到第 44 列所构成的矩形区域
  • 从上往下第 11 行到第 33 行、从左往右第 22 列到第 33 列所构成的矩形区域
  • 从上往下第 11 行到第 33 行、从左往右第 33 列到第 44 列所构成的矩形区域
  • 从上往下第 22 行到第 22 行、从左往右第 11 列到第 44 列所构成的矩形区域
  • 从上往下第 22 行到第 33 行、从左往右第 11 列到第 22 列所构成的矩形区域
  • 从上往下第 22 行到第 33 行、从左往右第 22 列到第 33 列所构成的矩形区域

约束条件

  • HH 和 WW 是介于 11 到 500500(含)之间的整数。
  • KK 是介于 00 到 HWHW(含)之间的整数。
  • SiS_i 是一个长度为 WW 的字符串,仅由字符 0 和 1 组成。

输入解题思路,AI测评打分。不知道怎么写?

首页