結果
問題 | No.1170 Never Want to Walk |
ユーザー | shotoyoo |
提出日時 | 2020-08-14 22:01:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 433 ms / 2,000 ms |
コード長 | 1,637 bytes |
コンパイル時間 | 276 ms |
コンパイル使用メモリ | 82,280 KB |
実行使用メモリ | 113,392 KB |
最終ジャッジ日時 | 2024-10-10 15:16:04 |
合計ジャッジ時間 | 9,228 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,864 KB |
testcase_01 | AC | 45 ms
52,864 KB |
testcase_02 | AC | 42 ms
52,864 KB |
testcase_03 | AC | 42 ms
52,480 KB |
testcase_04 | AC | 42 ms
52,480 KB |
testcase_05 | AC | 41 ms
52,480 KB |
testcase_06 | AC | 38 ms
52,608 KB |
testcase_07 | AC | 40 ms
52,480 KB |
testcase_08 | AC | 39 ms
52,736 KB |
testcase_09 | AC | 40 ms
52,520 KB |
testcase_10 | AC | 40 ms
52,608 KB |
testcase_11 | AC | 41 ms
52,736 KB |
testcase_12 | AC | 57 ms
63,872 KB |
testcase_13 | AC | 63 ms
67,584 KB |
testcase_14 | AC | 63 ms
68,096 KB |
testcase_15 | AC | 62 ms
63,744 KB |
testcase_16 | AC | 57 ms
64,740 KB |
testcase_17 | AC | 63 ms
68,608 KB |
testcase_18 | AC | 55 ms
63,872 KB |
testcase_19 | AC | 59 ms
65,280 KB |
testcase_20 | AC | 73 ms
73,984 KB |
testcase_21 | AC | 58 ms
64,640 KB |
testcase_22 | AC | 64 ms
71,040 KB |
testcase_23 | AC | 71 ms
74,240 KB |
testcase_24 | AC | 69 ms
73,088 KB |
testcase_25 | AC | 63 ms
70,656 KB |
testcase_26 | AC | 72 ms
74,576 KB |
testcase_27 | AC | 396 ms
112,484 KB |
testcase_28 | AC | 389 ms
112,560 KB |
testcase_29 | AC | 402 ms
112,572 KB |
testcase_30 | AC | 433 ms
112,468 KB |
testcase_31 | AC | 423 ms
113,088 KB |
testcase_32 | AC | 340 ms
112,352 KB |
testcase_33 | AC | 340 ms
112,368 KB |
testcase_34 | AC | 348 ms
113,028 KB |
testcase_35 | AC | 361 ms
112,692 KB |
testcase_36 | AC | 343 ms
112,612 KB |
testcase_37 | AC | 314 ms
113,392 KB |
testcase_38 | AC | 327 ms
113,008 KB |
ソースコード
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,a,b = list(map(int, input().split())) xs = list(map(int, input().split())) ls = [None]*n rs = [None]*n j = 0 for i in range(n): x = xs[i] while j+1<n and xs[j]<x+a: j += 1 if x+a<=xs[j]<=x+b: ls[i] = j j = 0 for i in range(n): x = xs[i] while j+1<n and xs[j+1]<=x+b: j += 1 if x+a<=xs[j]<=x+b: rs[i] = j class UnionFindTree: def __init__(self, n): self.n = n self.parent = list(range(n)) self.size = [1] * n def root(self, i): inter = set() while self.parent[i]!=i: inter.add(i) i = self.parent[i] r = i for i in inter: self.parent[i] = r return r def connect(self, i, j): if i==j: return ri = self.root(i) rj = self.root(j) if ri==rj: return if self.size[ri]<self.size[rj]: self.parent[ri] = rj self.size[rj] += self.size[ri] else: self.parent[rj] = ri self.size[ri] += self.size[rj] uf = UnionFindTree(n) pl, pr = -1, -1 for i, (l,r) in enumerate(zip(ls,rs)): if l is not None and (l<=pr): uf.connect(i, i-1) for j in range(pr, r+1): uf.connect(i, j) elif l is not None: for j in range(l, r+1): uf.connect(i, j) else: pass if l is not None: pl,pr = l,r for i in range(n): print(uf.size[uf.root(i)])