結果
問題 | No.2923 Mayor's Job |
ユーザー |
|
提出日時 | 2024-10-12 16:03:23 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,538 ms / 2,000 ms |
コード長 | 832 bytes |
コンパイル時間 | 115 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 107,392 KB |
最終ジャッジ日時 | 2024-10-12 16:03:41 |
合計ジャッジ時間 | 11,857 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
def dfs(x, prev, h): for to_x in to[x]: if to_x != prev and (to_x not in delete) and H[to_x] < h: delete.add(to_x) dfs(to_x, x, H[to_x]) ########################################################################## import sys; sys.setrecursionlimit(10**7) from heapq import heapify, heappop, heappush from math import dist N, K = map(int,input().split()) H = list(map(int,input().split())) XY = [list(map(int,input().split())) for _ in range(N)] to = [[] for _ in range(N)] for i in range(N-1): for j in range(i+1, N): if dist(XY[i], XY[j]) <= K: to[i].append(j) to[j].append(i) delete = set() Hi = [(-H[i], i) for i in range(N)] heapify(Hi) ans = 0 while Hi: h, i = heappop(Hi) if i not in delete: ans += 1 dfs(i, -1, -h) print(ans)