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

26002번 - Kiosk Construction 스페셜 저지다국어

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

문제

You are planning to start a Beautifully Arranged Placid Camping. You already have bought a field, which you have divided into a $h \times w$-grid of plots, and numbered them with distinct numbers $a_{ij}$ from 1ドル$ to $h \cdot w$. However, you forgot one thing: you still need to place the reception kiosk at one of the plots. You want to minimise the maximal distance that any guest will walk from the reception kiosk to their plot. Guests will however not take the shortest path to their plot, but instead they follow the following procedure, starting at the reception kiosk:

  • Look at the numbers of the four neighbouring plots.
  • Go to the plot with the number closest to the destination number. In case of a tie, out of the two tying plots, go to the one with the number closest to the current plot number.
  • Repeat until the destination is reached.

Note that this procedure might not terminate in some cases.

Given the numbering of the plots, find the plot number of the optimal position for the reception kiosk and the maximal walking distance to any plot from this kiosk. If, for every possible position for the reception kiosk, there is at least one plot for which the procedure outlined above does not terminate, output that this is impossible.

Figure K.1 shows the third sample case: one solution is to put the kiosk in plot 4ドル,ドル so that every other plot is at most distance 3ドル$ away. Placing the kiosk in plot 7ドル$ does not work as plot 9ドル$ cannot be reached from there.

Figure K.1: Visualisation of the third sample case.

입력

The input consists of:

  • One line with two integers $h$ and $w$ (2ドル\leq h, w\leq 40$), the dimensions of the camping.
  • $h$ lines, the $i$th of which contains $w$ integers $a_{i, 1}, \ldots, a_{i, n}$ (1ドル \leq a_{i, j} \leq h \cdot w$), the plot numbers. It is guaranteed that all numbers from 1ドル$ to $h \cdot w$ occur exactly once.

출력

If there is a position for the reception kiosk such that every other plot can be reached, then output the optimal position for the reception kiosk and the corresponding maximal walking distance. Otherwise, output "impossible".

If there are multiple valid solutions, you may output any one of them.

제한

예제 입력 1

2 3
1 2 3
6 5 4

예제 출력 1

2 2

예제 입력 2

3 3
1 4 8
7 5 2
3 9 6

예제 출력 2

impossible

예제 입력 3

3 3
9 3 1
4 7 2
8 6 5

예제 출력 3

4 3

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2022 K번

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

출처

대학교 대회

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

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