結果
問題 | No.1170 Never Want to Walk |
ユーザー | qumazaki |
提出日時 | 2020-09-05 20:20:42 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 354 ms / 2,000 ms |
コード長 | 2,175 bytes |
コンパイル時間 | 521 ms |
コンパイル使用メモリ | 87,300 KB |
実行使用メモリ | 137,572 KB |
最終ジャッジ日時 | 2023-08-19 13:01:44 |
合計ジャッジ時間 | 8,478 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
70,828 KB |
testcase_01 | AC | 64 ms
71,032 KB |
testcase_02 | AC | 65 ms
71,188 KB |
testcase_03 | AC | 63 ms
70,968 KB |
testcase_04 | AC | 64 ms
71,212 KB |
testcase_05 | AC | 61 ms
71,112 KB |
testcase_06 | AC | 66 ms
70,824 KB |
testcase_07 | AC | 67 ms
71,184 KB |
testcase_08 | AC | 66 ms
71,004 KB |
testcase_09 | AC | 65 ms
71,004 KB |
testcase_10 | AC | 63 ms
71,256 KB |
testcase_11 | AC | 61 ms
71,304 KB |
testcase_12 | AC | 78 ms
75,248 KB |
testcase_13 | AC | 79 ms
75,308 KB |
testcase_14 | AC | 77 ms
75,636 KB |
testcase_15 | AC | 70 ms
75,268 KB |
testcase_16 | AC | 73 ms
75,484 KB |
testcase_17 | AC | 74 ms
75,404 KB |
testcase_18 | AC | 72 ms
75,236 KB |
testcase_19 | AC | 75 ms
75,076 KB |
testcase_20 | AC | 77 ms
75,284 KB |
testcase_21 | AC | 71 ms
75,304 KB |
testcase_22 | AC | 78 ms
75,328 KB |
testcase_23 | AC | 74 ms
75,584 KB |
testcase_24 | AC | 90 ms
75,208 KB |
testcase_25 | AC | 77 ms
75,268 KB |
testcase_26 | AC | 77 ms
75,776 KB |
testcase_27 | AC | 352 ms
136,156 KB |
testcase_28 | AC | 295 ms
134,740 KB |
testcase_29 | AC | 354 ms
136,824 KB |
testcase_30 | AC | 310 ms
136,172 KB |
testcase_31 | AC | 308 ms
134,248 KB |
testcase_32 | AC | 236 ms
135,256 KB |
testcase_33 | AC | 275 ms
134,992 KB |
testcase_34 | AC | 278 ms
136,724 KB |
testcase_35 | AC | 255 ms
136,340 KB |
testcase_36 | AC | 251 ms
134,956 KB |
testcase_37 | AC | 265 ms
135,824 KB |
testcase_38 | AC | 254 ms
137,572 KB |
ソースコード
import sys sys.setrecursionlimit(10**9) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self,x): if(self.parents[x] < 0): return x self.parents[x] = self.find(self.parents[x]) return self.parents[x] def size(self, x): return self.parents[ self.find(x) ] * -1 def same(self, x, y): x_root = self.find(x) y_root = self.find(y) return (x_root == y_root) def union(self,x,y): x_root = self.find(x) y_root = self.find(y) if(x_root == y_root): return if( self.parents[x_root] <= self.parents[y_root] ): self.parents[x_root] += self.parents[y_root] self.parents[y_root] = x_root else: self.parents[y_root] += self.parents[x_root] self.parents[x_root] = y_root def members(self,x): root = self.find(x) ret = [ i for i in range(self.n) if self.find(i) == root ] return ret def roots(self): ret = [ i for i in range(self.n) if self.parents[i] < 0] return ret def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} n,a,b = map(int,input().split()) x = list(map(int,input().split())) cango = [[0,0,0,0] for _ in range(n)] ll,l,r,rr = 0,0,0,0 for i,xi in enumerate(x): while(x[ll] < xi-b): ll += 1 while(x[l] <= xi-a): l += 1 if(r < n): while(x[r] < xi+a): r += 1 if(r==n): break if(rr < n): while(x[rr] <= xi+b): rr += 1 if(rr==n): break cango[i] = [ll,l,r,rr] uf = UnionFind(n) for i in range(n): r,rr = cango[i][2:4] for j in range(rr-1,r-1,-1): if(uf.same(i,j)): break uf.union(i,j) for i in range(n-1,-1,-1): ll,l = cango[i][0:2] for j in range(ll,l): if(uf.same(i,j)): break uf.union(i,j) ans = [0] * n for i in range(n): ans[i] = uf.size(i) print('\n'.join(map(str,ans)))