結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー | 👑 Kazun |
提出日時 | 2021-01-23 00:45:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 638 ms / 2,000 ms |
コード長 | 3,490 bytes |
コンパイル時間 | 574 ms |
コンパイル使用メモリ | 86,812 KB |
実行使用メモリ | 114,516 KB |
最終ジャッジ日時 | 2023-08-28 12:03:21 |
合計ジャッジ時間 | 17,191 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
71,308 KB |
testcase_01 | AC | 73 ms
71,296 KB |
testcase_02 | AC | 72 ms
71,280 KB |
testcase_03 | AC | 74 ms
71,268 KB |
testcase_04 | AC | 74 ms
71,340 KB |
testcase_05 | AC | 73 ms
71,272 KB |
testcase_06 | AC | 73 ms
71,344 KB |
testcase_07 | AC | 73 ms
71,400 KB |
testcase_08 | AC | 73 ms
71,364 KB |
testcase_09 | AC | 73 ms
71,256 KB |
testcase_10 | AC | 72 ms
71,264 KB |
testcase_11 | AC | 73 ms
71,348 KB |
testcase_12 | AC | 74 ms
71,416 KB |
testcase_13 | AC | 236 ms
81,552 KB |
testcase_14 | AC | 215 ms
81,668 KB |
testcase_15 | AC | 130 ms
79,016 KB |
testcase_16 | AC | 95 ms
78,672 KB |
testcase_17 | AC | 205 ms
81,076 KB |
testcase_18 | AC | 189 ms
81,188 KB |
testcase_19 | AC | 222 ms
81,904 KB |
testcase_20 | AC | 145 ms
78,564 KB |
testcase_21 | AC | 213 ms
82,548 KB |
testcase_22 | AC | 201 ms
80,112 KB |
testcase_23 | AC | 303 ms
95,284 KB |
testcase_24 | AC | 412 ms
102,568 KB |
testcase_25 | AC | 567 ms
110,336 KB |
testcase_26 | AC | 470 ms
103,288 KB |
testcase_27 | AC | 461 ms
95,316 KB |
testcase_28 | AC | 315 ms
86,940 KB |
testcase_29 | AC | 306 ms
89,080 KB |
testcase_30 | AC | 638 ms
114,384 KB |
testcase_31 | AC | 631 ms
114,516 KB |
testcase_32 | AC | 459 ms
108,656 KB |
testcase_33 | AC | 525 ms
103,328 KB |
testcase_34 | AC | 466 ms
99,320 KB |
testcase_35 | AC | 399 ms
102,996 KB |
testcase_36 | AC | 557 ms
110,604 KB |
testcase_37 | AC | 284 ms
87,132 KB |
testcase_38 | AC | 311 ms
101,780 KB |
testcase_39 | AC | 598 ms
110,840 KB |
testcase_40 | AC | 596 ms
110,472 KB |
testcase_41 | AC | 534 ms
110,828 KB |
testcase_42 | AC | 474 ms
94,608 KB |
testcase_43 | AC | 73 ms
71,408 KB |
testcase_44 | AC | 267 ms
108,440 KB |
testcase_45 | AC | 144 ms
79,864 KB |
ソースコード
class Coloring_Union_Find(): def __init__(self,N,f,e=0): """0,1,...,n-1を要素として初期化する. N:要素数 f:2変数関数の合成 e:最初の値 """ self.n=N self.parents=[-1]*N self.data=[e]*N self.rank=[0]*N self.f=f def find(self, x): """要素xの属している族を調べる. x:要素 """ V=[] while self.parents[x]>=0: V.append(x) x=self.parents[x] for v in V: self.parents[v]=x return x def union(self, x, y): """要素x,yを同一視する. x,y:要素 """ x=self.find(x) y=self.find(y) if x==y: return self.data[x]=self.data[y]=self.f(self.data[x],self.data[y]) if self.rank[x]<self.rank[y]: x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x if self.rank[x]==self.rank[y]: self.rank[x]+=1 def size(self, x): """要素xの属している要素の数. x:要素 """ return -self.parents[self.find(x)] def same(self, x, y): """要素x,yは同一視されているか? x,y:要素 """ return self.find(x) == self.find(y) def set(self,x,c): """要素xの属する成分の色をcに変更する. x:要素 c:色 """ self.data[self.find(x)]=c return def look(self,x): """要素xの属する成分の色 x:要素 """ return self.data[self.find(x)] def members(self, x): """要素xが属している族の要素. ※族の要素の個数が欲しいときはsizeを使うこと!! x:要素 """ root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): """族の名前のリスト """ return [i for i,x in enumerate(self.parents) if x < 0] def group_count(self): """族の個数 """ return len(self.roots()) def all_group_members(self): """全ての族の出力 """ X={r:[] for r in self.roots()} for k in range(self.n): X[self.find(k)].append(k) return X def color_list(self): return [self.look(x) for x in range(self.n)] def color_map(self): return {x:self.look(x) for x in self.roots()} def __str__(self): return '\n'.join('{} [color:{}]: {}'.format(r,self.look(r),self.members(r)) for r in self.roots()) def __repr__(self): return self.__str__() #================================================ import sys input=sys.stdin.readline write=sys.stdout.write N=int(input()) A=["*"]+list(map(int,input().split())) B=["*"]+list(map(int,input().split())) P=["*"]+list(map(int,input().split())) inf=float("inf") U=Coloring_Union_Find(N+1,lambda x,y:[x[0]+y[0],x[1]+y[1]],[0,0]) Ans=0 for i in range(1,N+1): d=A[i]-B[i] Ans+=d*d*P[i] if P[i]!=0: U.set(i,[d,1/P[i]]) else: U.set(i,[d,inf]) Q=int(input()) S=[0]*Q for q in range(Q): X,Y=map(int,input().split()) if not U.same(X,Y): d,p=U.look(X) Ans-=d*d/p d,p=U.look(Y) Ans-=d*d/p U.union(X,Y) d,p=U.look(X) Ans+=d*d/p Ans=max(0,Ans) S[q]=Ans write("\n".join(map(str,S)))