結果
問題 | No.1170 Never Want to Walk |
ユーザー | tktk_snsn |
提出日時 | 2020-08-14 22:28:32 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,449 ms / 2,000 ms |
コード長 | 1,629 bytes |
コンパイル時間 | 99 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 77,208 KB |
最終ジャッジ日時 | 2024-04-18 22:19:04 |
合計ジャッジ時間 | 19,880 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
11,136 KB |
testcase_01 | AC | 32 ms
11,008 KB |
testcase_02 | AC | 32 ms
11,008 KB |
testcase_03 | AC | 30 ms
11,136 KB |
testcase_04 | AC | 30 ms
11,136 KB |
testcase_05 | AC | 30 ms
11,008 KB |
testcase_06 | AC | 30 ms
11,008 KB |
testcase_07 | AC | 30 ms
11,136 KB |
testcase_08 | AC | 32 ms
11,136 KB |
testcase_09 | AC | 31 ms
11,008 KB |
testcase_10 | AC | 30 ms
11,008 KB |
testcase_11 | AC | 30 ms
11,008 KB |
testcase_12 | AC | 37 ms
11,264 KB |
testcase_13 | AC | 37 ms
11,392 KB |
testcase_14 | AC | 37 ms
11,136 KB |
testcase_15 | AC | 36 ms
11,264 KB |
testcase_16 | AC | 36 ms
11,392 KB |
testcase_17 | AC | 36 ms
11,264 KB |
testcase_18 | AC | 36 ms
11,264 KB |
testcase_19 | AC | 37 ms
11,264 KB |
testcase_20 | AC | 36 ms
11,136 KB |
testcase_21 | AC | 36 ms
11,264 KB |
testcase_22 | AC | 37 ms
11,136 KB |
testcase_23 | AC | 38 ms
11,264 KB |
testcase_24 | AC | 37 ms
11,136 KB |
testcase_25 | AC | 37 ms
11,264 KB |
testcase_26 | AC | 37 ms
11,264 KB |
testcase_27 | AC | 1,391 ms
75,500 KB |
testcase_28 | AC | 1,380 ms
74,708 KB |
testcase_29 | AC | 1,402 ms
76,404 KB |
testcase_30 | AC | 1,405 ms
76,620 KB |
testcase_31 | AC | 1,377 ms
74,520 KB |
testcase_32 | AC | 1,407 ms
75,764 KB |
testcase_33 | AC | 1,401 ms
74,492 KB |
testcase_34 | AC | 1,449 ms
77,208 KB |
testcase_35 | AC | 1,408 ms
76,100 KB |
testcase_36 | AC | 1,389 ms
74,448 KB |
testcase_37 | AC | 1,361 ms
71,416 KB |
testcase_38 | AC | 1,426 ms
71,312 KB |
ソースコード
import bisect from collections import deque class UF_tree: def __init__(self, n): self.root = [-1] * (n + 1) # -1ならそのノードが根,で絶対値が木の要素数 self.rank = [0] * (n + 1) def find(self, x): # xの根となる要素番号を返す if self.root[x] < 0: return x else: self.root[x] = self.find(self.root[x]) return self.root[x] def isSame(self, x, y): return self.find(x) == self.find(y) def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] < self.rank[y]: self.root[y] += self.root[x] self.root[x] = y else: self.root[x] += self.root[y] self.root[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def size(self, x): return -self.root[self.find(x)] N, A, B = map(int, input().split()) X = list(map(int, input().split())) uf = UF_tree(N) upper = [] lower = [] for i, xi in enumerate(X): l = bisect.bisect_left(X, xi + A) r = bisect.bisect_right(X, xi + B) if l < r: uf.unite(i, l) upper.append((l, r)) l = bisect.bisect_left(X, xi - B) r = bisect.bisect_right(X, xi - A) if l < r: uf.unite(i, l) lower.append((l, r)) for p, q in zip(range(N - 1), range(1, N)): _, pr = upper[p] ql, _ = upper[q] if pr > ql: uf.unite(p, q) _, pr = lower[p] ql, _ = lower[q] if pr > ql: uf.unite(p, q) for i in range(N): print(uf.size(i))