루미 알고리즘

#1408플래티넘Solnedgång

PO 2016 온라인 예선코딩출제 Aron Granberg영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

You are visiting a very warm country, and it happens to be a sizzling hot day. Luckily, you managed to find the shadow of a house to take cover in. You realize that you probably should head back to the hotel sometime soon, but you also realize that it's too hot to walk in the sun. The city you are in consists of N houses, placed in a grid, where every house occupies exactly one unit square.

Currently, each house has a shadow that is exactly one unit square long, and is located directly north of the house. Since the sun just started to set, this shadow will extend one more unit square north per time unit. You can walk from the shadow of one house to another one, if the shadows share an edge of length at least one (see figure). You cannot walk through houses.

The question is how long it will take before there exists a path to the hotel that does not involve getting burned by the sun. The hotel is house number N, and you are currently in the shadow of house number 1. Since the hotel entrence is at the north side of the house, that's where you need to go. In the worst case you might have to wait until nightfall, which will occur in K units of time.

(그림은 원문 저장소에서 볼 수 있습니다)

The first line contains two space-separated integers N and K - the number of houses in the city and the number of time units before nightfall.

The next N lines contains 2 integers x y each, the coordinates of the houses. The first line contains the coordinates of the house which you take cover behind, and the last line contains the coordinate of the hotel.

It is guaranteed that every house has a shadow, i.e. no house is placed immediately south of another house.

Output

You should output a single integer, the time it takes before there exist a path to the hotell which goes entirely through the shadows, or "NATT" in case this time exceeds or equals K.

Scoring

Your solution will be tested on a number of test case groups. To get points for a group you have to solve all the test cases in that group.

For all groups it holds that 1 ≤ N, 0 ≤ K.

GroupPointsLimits
119N, K ≤ 100, 0 ≤ x, y ≤ 100
226N, K ≤ 1000, 0 ≤ x, y ≤ 1000
317N, K ≤ 1000, 0 ≤ x, y ≤ 100000
423N ≤ 20000, K ≤ 10^7, 0 ≤ x, y ≤ 10^7
515N ≤ 300000, K ≤ 10^18, 0 ≤ x, y ≤ 10^18

예제

예제 1

입력
4 10
0 1
1 2
2 0
3 2
출력
2

예제 2

입력
8 10
1 0
2 1
3 1
4 1
2 4
3 4
1 5
0 4
출력
3

예제 3

입력
2 100
1 0
3 0
출력
NATT

출처 표기

출처: Programmeringsolympiaden 2016년 온라인 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.