結果
問題 | No.1170 Never Want to Walk |
ユーザー | qumazaki |
提出日時 | 2020-09-05 20:00:15 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,173 bytes |
コンパイル時間 | 227 ms |
コンパイル使用メモリ | 82,832 KB |
実行使用メモリ | 136,980 KB |
最終ジャッジ日時 | 2024-11-29 06:00:51 |
合計ジャッジ時間 | 7,287 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
53,440 KB |
testcase_01 | AC | 35 ms
53,832 KB |
testcase_02 | AC | 36 ms
52,460 KB |
testcase_03 | AC | 34 ms
53,132 KB |
testcase_04 | AC | 35 ms
53,876 KB |
testcase_05 | WA | - |
testcase_06 | AC | 38 ms
52,952 KB |
testcase_07 | AC | 36 ms
53,888 KB |
testcase_08 | AC | 34 ms
53,252 KB |
testcase_09 | AC | 33 ms
53,340 KB |
testcase_10 | AC | 35 ms
54,112 KB |
testcase_11 | AC | 37 ms
54,116 KB |
testcase_12 | AC | 49 ms
63,844 KB |
testcase_13 | AC | 51 ms
67,608 KB |
testcase_14 | AC | 49 ms
67,336 KB |
testcase_15 | AC | 47 ms
64,444 KB |
testcase_16 | AC | 46 ms
65,604 KB |
testcase_17 | AC | 48 ms
67,680 KB |
testcase_18 | AC | 44 ms
63,792 KB |
testcase_19 | AC | 45 ms
65,528 KB |
testcase_20 | AC | 48 ms
68,168 KB |
testcase_21 | AC | 47 ms
66,032 KB |
testcase_22 | AC | 50 ms
67,412 KB |
testcase_23 | AC | 50 ms
67,848 KB |
testcase_24 | AC | 49 ms
66,996 KB |
testcase_25 | AC | 48 ms
67,368 KB |
testcase_26 | AC | 50 ms
69,000 KB |
testcase_27 | AC | 295 ms
134,572 KB |
testcase_28 | AC | 271 ms
133,296 KB |
testcase_29 | AC | 330 ms
135,440 KB |
testcase_30 | AC | 272 ms
135,144 KB |
testcase_31 | AC | 265 ms
133,256 KB |
testcase_32 | AC | 215 ms
134,096 KB |
testcase_33 | AC | 242 ms
134,216 KB |
testcase_34 | AC | 236 ms
135,848 KB |
testcase_35 | AC | 228 ms
135,292 KB |
testcase_36 | AC | 223 ms
133,540 KB |
testcase_37 | AC | 237 ms
134,856 KB |
testcase_38 | AC | 227 ms
136,980 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)))