問題一覧 > 通常問題

No.2095 High Rise

レベル : / AI推定難易度 : 1400 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 129
作問者 : 👑 箱星 / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 7205 / 自分の提出
問題文最終更新日: 2022-09-30 18:22:22
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 363 (順位表) の他の問題:

Problem Statement

There is an apartment building with $N$ floors, and each floor has $M$ rooms.

Since this building had no elevator, it has been decided to install new elevators. For this purpose, some rooms will be demolished to make space for the elevators.

Demolishing the $j$-th room on floor $i$ costs $A_{i,j}$.

After demolishing rooms, elevators are installed as follows.

  • For $i_1,i_2,j \ (1\le i_1\lt i_2\le N, 1\le j\le M)$, if the $j$-th rooms on floors $i_1,i_1+1,\ldots,i_2$ have all been demolished, an elevator can be installed at this location. This makes it possible to travel among floors $i_1,i_1+1,\ldots,i_2$.
  • Multiple elevators may be installed.

We want to make it possible to reach every floor from floor $1$ using elevators. Multiple elevators may be used.

Find the minimum total cost of demolishing rooms required to make every floor reachable from floor $1$.

Constraints

  • $1\le N,M\le 1000$
  • $1\le A_i\le 10^9$
  • All inputs are integers

Input

$N$ $M$
$A_{1,1}$ $A_{1,2}$ $\ldots$ $A_{1,M}$
$A_{2,1}$ $A_{2,2}$ $\ldots$ $A_{2,M}$
$\vdots$
$A_{N,1}$ $A_{N,2}$ $\ldots$ $A_{N,M}$

Output

Output the minimum cost of demolishing rooms required to make every floor reachable from floor $1$.

Sample

Sample 1
Input
3 4
9 9 9 1
1 9 9 1
1 9 9 9
Output
4

It suffices to demolish all rooms whose demolition cost is $1$.

Sample 2
Input
4 3
2 3 6
2 3 6
6 3 2
6 3 2
Output
12

Sample 3
Input
1 1
998244353
Output
0

No rooms need to be demolished.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。