Logo
(追記) (追記ここまで)

27588번 - Restaurant Opening 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB13812310791.453%

문제

Image by wirestock on Freepik

It is said that the three most important factors for determining whether or not a business will be successful are location, location, and location. The Incredible Cooks Preparing Cuisine are opening a new restaurant in the International City Promoting Cooking, and they have hired you to find the optimal location for their restaurant.

You decide to model the city as a grid, with each grid square having a specified number of people living in it. The distance between two grid squares $(r_1,c_1)$ and $(r_2,c_2)$ is $|r_1-r_2|+|c_1-c_2|.$ In order to visit the restaurant, each potential customer would incur a cost equal to the minimum distance from the grid square in which they live to the grid square containing the proposed location of the restaurant. The total cost for a given restaurant location is defined as the sum of the costs of everyone living in the city to visit the restaurant.

Given the current city layout, compute the minimum total cost if the Incredible Cooks Preparing Cuisine select their next restaurant location optimally.

입력

The first line of input contains two integers, $n$ and $m$ (1ドル < n,m \le 50$), where $n$ is the number of rows in the city grid and $m$ is the number of columns.

Each of the next $n$ lines contains $m$ integers $g_{ij}$ (0ドル\le g_{ij}\le 50$), which specifies the number of people living in the grid square at row $i,ドル column $j$.

출력

Output a single integer, which is the total cost if the restaurant is selected optimally.

제한

예제 입력 1

2 2
1 2
3 4

예제 출력 1

7

예제 입력 2

1 10
3 49 4 31 10 31 50 24 10 42

예제 출력 2

591

힌트

출처

ICPC > Regionals > North America > North Central North America Regional > 2022 North Central NA Regional Contest G번

ICPC > Regionals > North America > Pacific Northwest Regional > 2022 ICPC Pacific Northwest Region > Division 2 M번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /