結果
問題 | No.2523 Trick Flower |
ユーザー | MasKoaTS |
提出日時 | 2023-03-30 18:49:57 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,405 bytes |
コンパイル時間 | 302 ms |
コンパイル使用メモリ | 81,952 KB |
実行使用メモリ | 548,524 KB |
最終ジャッジ日時 | 2024-09-25 05:55:37 |
合計ジャッジ時間 | 7,210 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
61,200 KB |
testcase_01 | AC | 39 ms
53,496 KB |
testcase_02 | AC | 40 ms
53,816 KB |
testcase_03 | AC | 44 ms
53,288 KB |
testcase_04 | AC | 40 ms
53,628 KB |
testcase_05 | AC | 40 ms
53,000 KB |
testcase_06 | AC | 40 ms
53,820 KB |
testcase_07 | AC | 41 ms
53,604 KB |
testcase_08 | AC | 85 ms
76,536 KB |
testcase_09 | AC | 99 ms
76,408 KB |
testcase_10 | AC | 48 ms
60,932 KB |
testcase_11 | AC | 63 ms
67,580 KB |
testcase_12 | AC | 55 ms
65,784 KB |
testcase_13 | AC | 76 ms
76,320 KB |
testcase_14 | AC | 71 ms
74,064 KB |
testcase_15 | MLE | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
ソースコード
import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline import pypyjit pypyjit.set_param('max_unroll_recursion=-1') class SCC: def __init__(self, n): self.n = n self.graph = [[] for _ in range(n)] self.rev_graph = [[] for _ in range(n)] self.labels = [-1] * n self.lb_cnt = 0 def add_edge(self, v, nxt_v): self.graph[v].append(nxt_v) self.rev_graph[nxt_v].append(v) def build(self): self.post_order = [] self.used = [False] * self.n for v in range(self.n): if(self.used[v]): continue self._dfs(v) for v in reversed(self.post_order): if(self.labels[v] != -1): continue self._rev_dfs(v) self.lb_cnt += 1 def _dfs(self, v): stack = [v, 0] while(stack): v, idx = stack[-2:] if(not(idx) and self.used[v]): stack.pop() stack.pop() else: self.used[v] = True if(idx < len(self.graph[v])): stack[-1] += 1 stack.append(self.graph[v][idx]) stack.append(0) else: stack.pop() self.post_order.append(stack.pop()) def _rev_dfs(self, v): stack = [v] self.labels[v] = self.lb_cnt while stack: v = stack.pop() for nxt_v in self.rev_graph[v]: if(self.labels[nxt_v] != -1): continue stack.append(nxt_v) self.labels[nxt_v] = self.lb_cnt def construct(self): self.dag = [[] for i in range(self.lb_cnt)] self.groups = [[] for i in range(self.lb_cnt)] for v, lb in enumerate(self.labels): for nxt_v in self.graph[v]: nxt_lb = self.labels[nxt_v] if(lb == nxt_lb): continue self.dag[lb].append(nxt_lb) self.groups[lb].append(v) return self.dag, self.groups """ Main Code """ N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) c = list(map(int, input().split())) scc = SCC(N) for i, k in enumerate(c): scc.add_edge(k - 1, i) scc.build() dag, groups = scc.construct() n = len(groups) a = [0] * n b = [0] * n for i, g in enumerate(groups): a[i] = sum(A[k] for k in g) b[i] = sum(B[k] for k in g) def check(mid): visited = set([]) def get_dp(x): nonlocal visited; visited.add(x) ret = a[x] - mid * b[x] for y in dag[x]: ret += get_dp(y) return min(ret, 0) for i in range(n): if(i in visited or get_dp(i) == 0): continue return False return True ok = 0 ng = sum(a) // sum(b) + 1 while(ng - ok > 1): mid = (ok + ng) >> 1 if(check(mid)): ok = mid else: ng = mid print(ok)