cswork / OA打开练习工作台

MicrosoftOA #8

Find Suitable Locations

估计中等可在线判题

考点(AI 标注)网格搜索位运算

In the grid, 0 is an empty lot and 1 is a house. A store can be built on an empty lot whose Manhattan distance to every house is at most K. Find the number of suitable empty lots; if there are no houses, every empty lot qualifies.

输入格式

This site's input: the first line contains R C K (1≤R,C≤500, 0≤K≤1000), followed by R lines each with C values 0 or 1.

输出格式

Output a single integer, the answer.

样例 1

输入:

2 2 1
1 0
0 0

输出:

2

样例 2

输入:

1 1 0
0

输出:

1

样例 3

输入:

1 1 2
1

输出:

0

样例说明

Example 1: only the two empty lots to the right of and below the house are at distance 1; the bottom-right corner is at distance 2 and does not qualify, so the answer is 2.

Example 2: there are no houses, and the only empty lot satisfies every constraint, so the answer is 1.

Example 3: there are only houses and no empty lots, so the answer is 0.