CF1575M.Managing Telephone Poles
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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)×(m+1) . There is a telephone pole at (x,y) if ax,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 (x1,y1) and (x2,y2) is (x2−x1)2+(y2−y1)2 .
To optimize the building plan, the project supervisor asks you the sum of all S(x,y) for each 0≤x≤n and 0≤y≤m . Help him by finding the value of ∑x=0n∑y=0mS(x,y) .
输入格式
The first line contains two integers n and m ( 0≤n,m<2000 ) — the size of the grid.
Then (n+1) lines follow, each containing (m+1) integers ai,j ( 0≤ai,j≤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 ∑x=0n∑y=0mS(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, ∑x=0n∑y=0mS(x,y)=(0+1+4)+(1+2+5)+(0+1+4)=18 .