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

22373번 - Buttons 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB40171137.931%

문제

There is an $H \times W$ grid, with one button in each cell. Initially, all buttons are off. You will push them and turn them on.

Your task is to find a "good" timing of pressing the buttons. Let $t_{ij}$ be the timing to push the button of row $i$ and column $j$. The timing is said to be "good" if and only if the following conditions are satisfied.

  • $t_{ij}$ is an integer between 0ドル$ and 10ドル^9$ for all $i$ and $j$.
  • $t_{kl} + a_{ij} \le t_{ij} \le t_{kl} + b_{ij}$ for every cell $kl$ which is a horizontal or vertical neighbor of the cell $ij,ドル i.e., $|i - k| + |j - l| = 1$.

Write a program to output a "good" timing for the given $a$ and $b$. If there are several possible timings, you can output any of them. If there is no "good" timing, you should output $-1$.

입력

The input consists of a single test case of the following format.

$H$ $W$

$a_{11}$ $\dots$ $a_{1W}$

$\vdots$

$a_{H1}$ $\dots$ $a_{HW}$

$b_{11}$ $\dots$ $b_{1W}$

$\vdots$

$b_{H1}$ $\dots$ $b_{HW}$

$H$ and $W$ represent the height and width of the given grid ($w \le H, W \le 50$). $a_{ij}$ and $b_{ij}$ represent the range of time differences for the button of row $i$ and column $j$ ($-100,000 \le a_{ij} \le b_{ij} \le 100,000$).

출력

If there is a "good" timing, output it in the following format.

$T_{11}$ $\dots$ $T_{1W}$

$\vdots$

$T_{H1}$ $\dots$ $T_{HW}$

$T_{ij}$ is an integer representing the timing to push the button of row $i$ and column $j$. The timings should satisfy the conditions defined in the problem statement. If there are multiple correct answers, you can print any of them.

If there is no "good" timing, you should output $-1$ instead.

제한

예제 입력 1

3 3
-2 1 -2
1 -2 1
-2 1 -2
-1 2 -1
2 -1 2
-1 2 -1

예제 출력 1

0 1 0
1 0 2
0 2 0

예제 입력 2

2 2
1 1
1 1
1 1
1 1

예제 출력 2

-1

힌트

출처

Contest > ICPC Japanese Alumni Group > JAG Practice Contest for ICPC Asia Regional > JAG Practice Contest for ICPC 2020 Asia Yokohama Regional 2020 E번

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

출처

대학교 대회

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

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