結果
問題 | No.19 ステージの選択 |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2021-12-31 10:48:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 48 ms / 5,000 ms |
コード長 | 2,907 bytes |
コンパイル時間 | 964 ms |
コンパイル使用メモリ | 82,088 KB |
実行使用メモリ | 54,560 KB |
最終ジャッジ日時 | 2024-10-08 02:01:46 |
合計ジャッジ時間 | 2,906 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,832 KB |
testcase_01 | AC | 40 ms
52,900 KB |
testcase_02 | AC | 39 ms
52,264 KB |
testcase_03 | AC | 39 ms
52,684 KB |
testcase_04 | AC | 38 ms
53,340 KB |
testcase_05 | AC | 38 ms
53,344 KB |
testcase_06 | AC | 38 ms
53,508 KB |
testcase_07 | AC | 39 ms
54,500 KB |
testcase_08 | AC | 40 ms
53,940 KB |
testcase_09 | AC | 39 ms
52,776 KB |
testcase_10 | AC | 39 ms
54,560 KB |
testcase_11 | AC | 38 ms
52,548 KB |
testcase_12 | AC | 38 ms
53,568 KB |
testcase_13 | AC | 39 ms
52,776 KB |
testcase_14 | AC | 39 ms
53,220 KB |
testcase_15 | AC | 42 ms
53,236 KB |
testcase_16 | AC | 44 ms
52,304 KB |
testcase_17 | AC | 48 ms
54,220 KB |
testcase_18 | AC | 43 ms
53,652 KB |
testcase_19 | AC | 38 ms
53,592 KB |
testcase_20 | AC | 39 ms
54,200 KB |
testcase_21 | AC | 38 ms
52,436 KB |
testcase_22 | AC | 39 ms
53,052 KB |
testcase_23 | AC | 39 ms
53,044 KB |
ソースコード
import sys input = sys.stdin.readline class SCC: def __init__(self,n): self.n = n self.edges = [] def csr(self): self.start = [0]*(self.n+1) self.elist = [0]*len(self.edges) for e in self.edges: self.start[e[0]+1] += 1 for i in range(1,self.n+1): self.start[i] += self.start[i-1] counter = self.start[:] for e in self.edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 def add_edge(self,u,v): self.edges.append((u,v)) def scc_ids(self): self.csr() n = self.n now_ord = group_num = 0 visited = [] low = [0]*n order = [-1]*n ids = [0]*n parent = [-1]*n stack = [] for i in range(n): if order[i] == -1: stack.append(i) stack.append(i) while stack: v = stack.pop() if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(self.start[v],self.start[v+1]): to = self.elist[i] if order[to] == -1: stack.append(to) stack.append(to) parent[to] = v else: low[v] = min(low[v],order[to]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = n ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]],low[v]) for i,x in enumerate(ids): ids[i] = group_num-1-x return group_num,ids def scc(self): group_num,ids = self.scc_ids() groups = [[] for i in range(group_num)] for i,x in enumerate(ids): groups[x].append(i) return groups n = int(input()) L = [list(map(int,input().split())) for i in range(n)] L = [[l*10,x-1] for l,x in L] scc = SCC(n) for i in range(n): scc.add_edge(L[i][1],i) ans = 0 groups = scc.scc() done = [0]*n for g in groups: half = 0 mi = 10**10 s = 0 for i in g: mi = min(mi,L[i][0]) s += L[i][0] if done[L[i][1]]: half = 1 if half: ans += s//2 else: ans += (s-mi)//2+mi for i in g: done[i] = 1 ans = list(str(ans)) ans.insert(-1,".") print(*ans,sep="")