A14489 | Managing Telephone Poles
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Mr. Chanek's city can be represented as a plane. He wants to build a housing complex in the city.
There are some telephone poles on the plane, which is represented by a grid $a$ of size $(n + 1) \times (m + 1)$ . There is a telephone pole at $(x, y)$ if $a_{x, y} = 1$ .
For each point $(x, y)$ , define $S(x, y)$ as the square of the Euclidean distance between the nearest pole and $(x, y)$ . Formally, the square of the Euclidean distance between two points $(x_1, y_1)$ and $(x_2, y_2)$ is $(x_2 - x_1)^2 + (y_2 - y_1)^2$ .
To optimize the building plan, the project supervisor asks you the sum of all $S(x, y)$ for each $0 \leq x \leq n$ and $0 \leq y \leq m$ . Help him by finding the value of $\sum_{x=0}^{n} {\sum_{y=0}^{m} {S(x, y)}}$ .
There are some telephone poles on the plane, which is represented by a grid $a$ of size $(n + 1) \times (m + 1)$ . There is a telephone pole at $(x, y)$ if $a_{x, y} = 1$ .
For each point $(x, y)$ , define $S(x, y)$ as the square of the Euclidean distance between the nearest pole and $(x, y)$ . Formally, the square of the Euclidean distance between two points $(x_1, y_1)$ and $(x_2, y_2)$ is $(x_2 - x_1)^2 + (y_2 - y_1)^2$ .
To optimize the building plan, the project supervisor asks you the sum of all $S(x, y)$ for each $0 \leq x \leq n$ and $0 \leq y \leq m$ . Help him by finding the value of $\sum_{x=0}^{n} {\sum_{y=0}^{m} {S(x, y)}}$ .
输入格式
The first line contains two integers $n$ and $m$ ( $0 \leq n, m < 2000$ ) — the size of the grid.
Then $(n + 1)$ lines follow, each containing $(m + 1)$ integers $a_{i, j}$ ( $0 \leq a_{i, j} \leq 1$ ) — the grid denoting the positions of telephone poles in the plane. There is at least one telephone pole in the given grid.
Then $(n + 1)$ lines follow, each containing $(m + 1)$ integers $a_{i, j}$ ( $0 \leq a_{i, j} \leq 1$ ) — the grid denoting the positions of telephone poles in the plane. There is at least one telephone pole in the given grid.
输出格式
Output an integer denoting the value of $\sum_{x=0}^{n} {\sum_{y=0}^{m} {S(x, y)}}$ .
输入输出样例
输入 #1
2 2 101 000 000
输出 #1
18
输入 #2
5 4 10010 00000 01000 00001 00100 00010
输出 #2
36
In the first example, the nearest telephone pole for the points $(0,0)$ , $(1,0)$ , $(2,0)$ , $(0,1)$ , $(1,1)$ , and $(2,1)$ is at $(0, 0)$ . While the nearest telephone pole for the points $(0, 2)$ , $(1,2)$ , and $(2,2)$ is at $(0, 2)$ . Thus, $\sum_{x=0}^{n} {\sum_{y=0}^{m} {S(x, y)}} = (0 + 1 + 4) + (1 + 2 + 5) + (0 + 1 + 4) = 18$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted