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

24580번 - Land Equality 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB98333036.145%

문제

There is a kingdom where the old King wants to divide his land into two pieces and give them to his two descendants. The King’s land is a grid of r rows and c columns. Each cell in the grid has an integer value representing the prosperity of the cell, which can be 0 (deserted), 1 (regular), or 2 (fertile). Two cells are connected if they share a side horizontally or vertically.

Each descendant shall receive a single connected piece of land with at least one cell, in which all cells must be directly connected or indirectly connected via other cells. There shall be no leftover cells, which means that each cell must be given to one descendant. The prosperity of a piece of land is the product of all the prosperity values of its cells. The King wants the absolute difference between the prosperity of the two descendants’ land to be as small as possible. He has asked his best counselor to devise a land division plan between the two descendants.

입력

The first line of input contains two positive integers r and c (2 ≤ r × c ≤ 64). The next r lines each have c integers giving the prosperity values of the King’s land. All those integers are 0, 1, or 2.

출력

Output the smallest absolute difference between the prosperity of the two descendants’ land.

제한

예제 입력 1

3 4
1 2 1 1
2 2 1 2
1 2 2 2

예제 출력 1

8

예제 입력 2

2 3
0 1 2
0 1 2

예제 출력 2

0

예제 입력 3

1 3
2 0 2

예제 출력 3

2

힌트

출처

ICPC > Regionals > North America > Mid-Atlantic Regional > 2021 Mid-Atlantic USA Regional Contest D번

ICPC > Regionals > North America > North Central North America Regional > 2021 North Central NA Regional Contest E번

  • 문제를 만든 사람: Bowen Yu
(追記) (追記ここまで)

출처

대학교 대회

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

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