#P13647. [NOISG 2016] Fabric

[NOISG 2016] Fabric

题目描述

Kraw the Krow has a beautiful piece of fabric. The patterns are so intricate that every part of the fabric is different. However, after the Great Fire of 2017, the fabric now has a lot of unsightly holes. (The Great Fire was started, of course, by none other than Squeaky the Rat.)

Kraw wants to forget about the Great Fire, because he doesn’t like heat very much. He would like to cut out a rectangle of fabric and throw the rest away. The new piece of fabric must have an area of at least KK and cannot contain any holes.

Due to the gauge-antisymmetric properties of Kraw’s fabric (or something – Kraw can’t remember what the salesman said), Kraw can only cut the fabric along regular gridlines. Kraw wonders how many ways there are to cut a rectangle with an area of at least KK out of the fabric such that it contains no holes.

输入格式

Your program should read the input from standard input. The input consists of:

  • one line with three integers NN and MM (1N,M20001 \leq N, M \leq 2000), the height and width of the fabric, and KK (1KMN1 \leq K \leq MN), the minimum area of the rectangle in terms of the number of grid segments it must contain;
  • NN lines each with MM integers s0y,s1y,,s(M1)ys_{0y}, s_{1y}, \ldots, s_{(M-1)y}. sxys_{xy} is 11 if there is a hole on the segment with coordinates (x,y)(x, y), and 00 if there is no hole.

输出格式

Output one line with a single integer: the number of ways to cut a rectangle with an area of at least KK out of the fabric such that it contains no holes.

2 4 3
1 0 0 0
0 0 0 1
3

提示

Sample Explanation

3 rectangles with an area of at least 3 can possibly be cut from the fabric. Taking the top left segment as (0,0)(0, 0), there are:

  • 2 rectangles of area 3 — {(1,0),(2,0),(3,0)}\{(1, 0), (2, 0), (3, 0)\}, {(0,1),(1,1),(2,1)}\{(0, 1), (1, 1), (2, 1)\}
  • 1 rectangle of area 4 — {(1,0),(2,0),(1,1),(2,1)}\{(1, 0), (2, 0), (1, 1), (2, 1)\}

Subtasks

The maximum execution time on each instance is 1.0s. Your program will be tested on sets of input instances as follows:

Subtask Marks Restrictions
1 7 Each instance satisfies 0<N,M20000 < N, M \leq 2000, K=1K = 1 and sxy=0s_{xy} = 0 for all (x,y)(x, y);
2 9 Each instance satisfies 0<N,M20000 < N, M \leq 2000, K=1K = 1 and sxy=1s_{xy} = 1 for only one (x,y)(x, y);
3 12 Each instance satisfies 0<N,M500 < N, M \leq 50;
4 14 Each instance satisfies 0<N,M5000 < N, M \leq 500;
5 23 Each instance satisfies 0<N,M20000 < N, M \leq 2000 and K=1K = 1;
6 35 Each instance satisfies 0<N,M20000 < N, M \leq 2000.