結果
問題 |
No.3148 Min-Cost Destruction of Parentheses
|
ユーザー |
👑 |
提出日時 | 2025-05-14 18:12:46 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 636 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 82,640 KB |
実行使用メモリ | 131,964 KB |
最終ジャッジ日時 | 2025-05-15 23:08:42 |
合計ジャッジ時間 | 60,410 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 TLE * 2 |
ソースコード
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 from fractions import Fraction as F def f(w,a):return F(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)