問題一覧 > 通常問題

No.861 Cake Cutting

レベル : / AI推定難易度 : 1350 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 45
作問者 : nmnmnmnmnmnmnm / テスター : testestest
お気に入りにしたユーザー ProblemId : 2254 / 自分の提出
問題文最終更新日: 2018-10-25 18:19:49
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 219 (順位表) の他の問題:

Problem Statement

There is a square cake of size 5 rows by 5 columns, which A-kun and B-kun will share between the two of them.

The cell of the cake at row $i$, column $j$ has a fixed deliciousness $C_{ij}$.
The piece of cake at row $i$, column $j$ goes to either A-kun or B-kun.

Now, they decide to cut the cake and then divide it between the two of them.
Cuts can be made between rows and between columns, but there is a condition here.

The cake must be cut into two parts, one going to A-kun and one going to B-kun, and each part must be connected.
(Connected means that a piece of cake at some row i, column j is not cut off from the adjacent pieces of cake that share an edge with it.)

When the whole cake has been distributed to A-kun and B-kun with nothing left over, they want to minimize the difference between their respective total deliciousness values.
Find that difference (as a non-negative integer) when the cake is cut so as to minimize it.

Input

$C_{00}$ $C_{01}$ $C_{02}$ $C_{03}$ $C_{04}$
$C_{10}$ $C_{11}$ $C_{12}$ $C_{13}$ $C_{14}$
$C_{20}$ $C_{21}$ $C_{22}$ $C_{23}$ $C_{24}$
$C_{30}$ $C_{31}$ $C_{32}$ $C_{33}$ $C_{34}$
$C_{40}$ $C_{41}$ $C_{42}$ $C_{43}$ $C_{44}$

$C_{ij}$ is the deliciousness of the piece of cake at row $i$, column $j$.
$C_{ij}$ is a positive integer. $1 \le C_{ij} \le 1000000000=10^9$

Output

Output the answer on one line.
Print a newline at the end.

Sample

Sample 1
Input
3 5 4 1 6
6 3 4 3 1 
3 2 4 7 6
4 5 6 2 1
1 4 3 5 2
Output
1

For example, the cake can be cut as shown below. (The red lines are where it is cut.)
Both of the two parts of the cake are connected.

Sample 2
Input
8 2 4 3 1
3 3 8 7 2
1 3 6 6 2
4 5 9 2 5
2 3 3 4 2
Output
0

A donut-shaped cut like the one below is also possible.

Sample 3
Input
200 3 2 1 5
5 15 4 5 6
7 6 5 1 7
3 10 2 3 11
2 4 1 6 10
Output
76

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