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

30301번 - Sleeping Chameleons 다국어

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

문제

There are $N$ chameleons residing in the Chameleon Village, which can be viewed as the two dimensional plane. The $i$-th chameleon is located at $(X_i,Y_i)$ and has color $C_i$.

Deep into the night, only the first chameleon is awake, while all the other chameleons are asleep.

Suddenly, an urgent issue has arisen for the $N$-th chameleon, thus it needs to be awakened. Physical contact is required to wake up a chameleon. Therefore, to wake up a chameleon, other chameleon must either walk to its location, or extend its tongue to touch it.

Chameleons can move in eight directions: up, down, left, right, or diagonally. Specifically, a chameleon at $(x,y)$ can move to one of the following locations in one second: $(x-1,y-1),ドル $(x-1,y),ドル $(x-1,y+1),ドル $(x,y-1),ドル $(x,y),ドル $(x,y+1),ドル $(x+1,y-1),ドル $(x+1,y),ドル or $(x+1,y+1)$.

Additionally, a chameleon can extend its tongue vertically or horizontally. In other words, a chameleon at $(x,y)$ can extend its tongue to reach locations $(x+c,y)$ or $(x,y+c)$ for any integer $c$. Extending a tongue takes no time. However, chameleons of the same color are not easily visible, making it challenging to aim at each other, so they cannot extend its tongue towards each other. When extending the tongue, it doesn’t matter if there are other chameleons along the path; only the chameleon located at the destination of the tongue is awakened, and other chameleons along the path are not disturbed.

Since chameleons are sleepy, they immediately fall asleep at their current location after waking up another chameleon.

Determine the minimum number of seconds required to wake up the $N$-th chameleon.

입력

In the first line, the number of chameleons $N$ and the number of different colors $M$ are given, separated by space.

From the second line to the $(N+1)$-th line, the $(i+1)$-th line contains the initial positions $X_i,ドル $Y_i$ and color $C_i$ of the $i$-th chameleon, separated by space.

출력

Output the minimum time (in seconds) required to wake up the $N$-th chameleon.

제한

  • 2ドル\le N\le 100,円 000$
  • 1ドル\le M\le N$
  • $-10^9\le X_i,Y_i\le 10^9$ $(1\le i\le N)$
  • If $i\neq j,ドル $X_i\neq X_j$ or $Y_i\neq Y_j$. $(1\le i,j\le N)$
  • 1ドル\le C_i\le M$ $(1\le i\le N)$
  • For each 1ドル\le i\le M,ドル there exists 1ドル\le j\le N$ such that $C_j=i$.
  • All values in the input are integers.

예제 입력 1

7 3
-5 0 1
-3 3 2
6 10000 2
5 3 3
3 -7 3
0 3 2
7 0 1

예제 출력 1

4

The following is an explanation for the example. In the following way, it is possible to wake up the 7th chameleon in 4 seconds.

  • The 1st chameleon wakes up the 2nd chameleon by first walking from $(-5,0)$ to $(-3,0)$ in 2 seconds, then extending its tongue to $(-3,3)$.
  • The 2nd chameleon wakes up the 4th chameleon by extending its tongue from $(-3,3)$ to $(5,3)$. The 6th chameleon is sleeping in the middle of the path, but it does not get disturbed.
  • The 4th chameleon wakes up the 3rd chameleon by first walking from $(5,3)$ to $(6,4)$ in 1 second, then extending its tongue to $(6,10000)$.
  • The 3rd chameleon wakes up the 7th chameleon by walking from $(6,10000)$ to $(7,9999)$ in 1 second, then extending its tongue to $(7,0)$.

힌트

출처

University > KAIST > KAIST ICPC Mock Competition > 2023 KAIST 13th ICPC Mock Competition J번

Camp > Petrozavodsk Programming Camp > Summer 2024 > Day 2: K-ontest J번

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

출처

대학교 대회

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

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