아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Buttons

시간 제한2초메모리 제한512 MB

요약
각 격자 칸에 0 이상 10^9 이하의 정수 시각을 부여해 모든 인접한 두 칸이 t_kl + a_ij <= t_ij <= t_kl + b_ij를 만족하도록 하거나, 불가능하면 -1을 출력한다.
난이도

보통10점 중 5점

유형
최단 경로, 그래프, 이분 탐색, 그리디
정답자
아직 제출이 없습니다

문제

There is an H×WH \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_ijt\_{ij} be the timing to push the button of row ii and column jj. The timing is said to be "good" if and only if the following conditions are satisfied.

  • t_ijt\_{ij} is an integer between 00 and 10910^9 for all ii and jj.
  • t_kl+a_ij≤t_ij≤t_kl+b_ijt\_{kl} + a\_{ij} \le t\_{ij} \le t\_{kl} + b\_{ij} for every cell klkl which is a horizontal or vertical neighbor of the cell ijij, i.e., ∣i−k∣+∣j−l∣=1|i - k| + |j - l| = 1.

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

입력

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

HH WW

a_11a\_{11} …\dots a_1Wa\_{1W}

⋮\vdots

a_H1a\_{H1} …\dots a_HWa\_{HW}

b_11b\_{11} …\dots b_1Wb\_{1W}

⋮\vdots

b_H1b\_{H1} …\dots b_HWb\_{HW}

HH and WW represent the height and width of the given grid (w≤H,W≤50w \le H, W \le 50). a_ija\_{ij} and b_ijb\_{ij} represent the range of time differences for the button of row ii and column jj (−100,000≤a_ij≤b_ij≤100,000-100,000 \le a\_{ij} \le b\_{ij} \le 100,000).

출력

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

T_11T\_{11} …\dots T_1WT\_{1W}

⋮\vdots

T_H1T\_{H1} …\dots T_HWT\_{HW}

T_ijT\_{ij} is an integer representing the timing to push the button of row ii and column jj. 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-1 instead.

예제2

  1. 예제 1

    입력
    3 3
    -2 1 -2
    1 -2 1
    -2 1 -2
    -1 2 -1
    2 -1 2
    -1 2 -1
    
    예상 출력
    0 1 0
    1 0 2
    0 2 0
    
  2. 예제 2

    입력
    2 2
    1 1
    1 1
    1 1
    1 1
    
    예상 출력
    -1