結果
問題 | No.1170 Never Want to Walk |
ユーザー | Salmonize |
提出日時 | 2020-08-14 21:48:33 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 728 ms / 2,000 ms |
コード長 | 1,974 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 32,704 KB |
最終ジャッジ日時 | 2024-10-10 14:56:24 |
合計ジャッジ時間 | 11,816 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,880 KB |
testcase_01 | AC | 32 ms
10,880 KB |
testcase_02 | AC | 31 ms
10,752 KB |
testcase_03 | AC | 31 ms
10,752 KB |
testcase_04 | AC | 30 ms
10,752 KB |
testcase_05 | AC | 31 ms
10,752 KB |
testcase_06 | AC | 31 ms
10,880 KB |
testcase_07 | AC | 31 ms
10,752 KB |
testcase_08 | AC | 31 ms
10,880 KB |
testcase_09 | AC | 31 ms
10,880 KB |
testcase_10 | AC | 31 ms
10,752 KB |
testcase_11 | AC | 31 ms
10,880 KB |
testcase_12 | AC | 33 ms
10,752 KB |
testcase_13 | AC | 34 ms
11,008 KB |
testcase_14 | AC | 34 ms
11,008 KB |
testcase_15 | AC | 33 ms
11,008 KB |
testcase_16 | AC | 33 ms
11,008 KB |
testcase_17 | AC | 33 ms
10,880 KB |
testcase_18 | AC | 33 ms
11,008 KB |
testcase_19 | AC | 34 ms
11,008 KB |
testcase_20 | AC | 34 ms
11,008 KB |
testcase_21 | AC | 33 ms
11,008 KB |
testcase_22 | AC | 35 ms
10,880 KB |
testcase_23 | AC | 35 ms
10,880 KB |
testcase_24 | AC | 34 ms
10,880 KB |
testcase_25 | AC | 34 ms
10,880 KB |
testcase_26 | AC | 35 ms
11,008 KB |
testcase_27 | AC | 720 ms
31,936 KB |
testcase_28 | AC | 715 ms
31,632 KB |
testcase_29 | AC | 718 ms
32,524 KB |
testcase_30 | AC | 728 ms
32,300 KB |
testcase_31 | AC | 716 ms
31,696 KB |
testcase_32 | AC | 701 ms
31,836 KB |
testcase_33 | AC | 700 ms
31,676 KB |
testcase_34 | AC | 712 ms
32,428 KB |
testcase_35 | AC | 697 ms
32,196 KB |
testcase_36 | AC | 679 ms
31,860 KB |
testcase_37 | AC | 684 ms
31,648 KB |
testcase_38 | AC | 718 ms
32,704 KB |
ソースコード
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') class UnionFind: def __init__(self, n): self.ps = [-1] * (n + 1) def find(self, x): if self.ps[x] < 0: return x else: self.ps[x] = self.find(self.ps[x]) return self.ps[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.ps[x] > self.ps[y]: x, y = y, x self.ps[x] += self.ps[y] self.ps[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): x = self.find(x) return -self.ps[x] def solve(): n, a, b = nm() l = nl() uf = UnionFind(n) cur = -1 lef, rig = 0, 0 for i in range(n): while lef < n and l[lef] - l[i] < a: lef += 1 while rig + 1 < n and l[rig + 1] - l[i] <= b: rig += 1 for j in range(max(cur, lef), rig): uf.unite(j, j+1) # print('a', j, j+1) cur = rig if lef <= rig: uf.unite(i, lef) # print('b', i, lef) uf.unite(i, rig) # print('b', i, rig) # print(i, lef, rig) # cur = n # lef, rig = n-1, n-1 # for i in range(n-1, -1, -1): # while rig >= 0 and l[i] - l[rig] < a: # rig -= 1 # while lef > 0 and l[i] - l[lef-1] <= b: # lef -= 1 # for j in range(min(cur, rig), lef): # uf.unite(j, j-1) # cur = lef # if rig >= 0: # uf.unite(i, lef) # uf.unite(i, rig) # print(i, lef, rig) for i in range(n): print(uf.size(i)) return solve()