結果
問題 | No.3148 Min-Cost Destruction of Parentheses |
ユーザー |
👑 |
提出日時 | 2025-05-14 18:17:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,074 ms / 4,000 ms |
コード長 | 619 bytes |
コンパイル時間 | 226 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 100,324 KB |
最終ジャッジ日時 | 2025-05-15 23:08:48 |
合計ジャッジ時間 | 18,332 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#python -m pdb a.py R=range I=input J=lambda:list(map(int,I().split())) N=sum(J())+1 S=I() A=[0]+J() s=[0] p=[0]*N l=1 for c in S: if c<')':p[l]=s[-1];s+=[l];l+=1 else:s.pop() import heapq as h s=[0]*N q=[] P=list(R(N)) H=[0]*N def r(i): m=P[i] while i!=m:P[i]=i=P[m];m=P[i] return i w=[1]*N def f(w,a):return w/a if a else 9**6 for i in R(1,N):s[i]=f(1,A[i]);h.heappush(q,[s[i],i]) a=0 while q: t,v=h.heappop(q);v=r(v) if t!=s[v]:continue s[v]=0;u=r(p[v]);a+=w[u]*A[v];p[v]=p[u] if H[u]<H[v]:u,v=v,u H[u]+=H[u]==H[v];P[v]=u;A[u]+=A[v];w[u]+=w[v] if u!=r(0):s[u]=f(w[u],A[u]);h.heappush(q,[s[u],u]) print(a)