結果
問題 | No.2523 Trick Flower |
ユーザー | MasKoaTS |
提出日時 | 2023-10-26 17:11:05 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,376 bytes |
コンパイル時間 | 228 ms |
コンパイル使用メモリ | 82,200 KB |
実行使用メモリ | 250,248 KB |
最終ジャッジ日時 | 2024-09-25 12:25:58 |
合計ジャッジ時間 | 23,974 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,212 KB |
testcase_01 | AC | 40 ms
52,648 KB |
testcase_02 | AC | 36 ms
53,432 KB |
testcase_03 | AC | 38 ms
52,556 KB |
testcase_04 | AC | 35 ms
52,688 KB |
testcase_05 | AC | 36 ms
52,852 KB |
testcase_06 | AC | 37 ms
53,488 KB |
testcase_07 | AC | 40 ms
54,848 KB |
testcase_08 | AC | 127 ms
78,152 KB |
testcase_09 | AC | 226 ms
81,088 KB |
testcase_10 | AC | 44 ms
61,096 KB |
testcase_11 | AC | 124 ms
78,420 KB |
testcase_12 | AC | 89 ms
76,504 KB |
testcase_13 | AC | 119 ms
78,236 KB |
testcase_14 | AC | 124 ms
78,200 KB |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 271 ms
133,424 KB |
testcase_18 | AC | 226 ms
122,584 KB |
testcase_19 | AC | 2,119 ms
215,536 KB |
testcase_20 | AC | 1,434 ms
201,536 KB |
testcase_21 | AC | 3,585 ms
250,248 KB |
testcase_22 | AC | 1,139 ms
172,792 KB |
testcase_23 | AC | 1,724 ms
188,928 KB |
testcase_24 | AC | 886 ms
144,672 KB |
testcase_25 | AC | 436 ms
188,628 KB |
testcase_26 | AC | 1,766 ms
175,840 KB |
testcase_27 | AC | 754 ms
191,180 KB |
testcase_28 | AC | 2,123 ms
183,892 KB |
testcase_29 | AC | 151 ms
91,536 KB |
testcase_30 | AC | 1,214 ms
152,992 KB |
testcase_31 | AC | 338 ms
84,420 KB |
testcase_32 | AC | 607 ms
127,772 KB |
testcase_33 | AC | 1,564 ms
175,280 KB |
ソースコード
import sys input = sys.stdin.readline class SCC: def __init__(self, n): self.n = n self.route = [[] for _ in [0] * n] self.rev_route = [[] for _ in [0] * n] self.label = [-1] * n self.count = 0 def add_edge(self, v_first, v_second): self.route[v_first].append(v_second) self.rev_route[v_second].append(v_first) def _build(self): self.v_list = [] self.visited = set([]) for v in range(self.n): if(v in self.visited): continue self._dfs(v) for v in reversed(self.v_list): if(self.label[v] != -1): continue self._rev_dfs(v) self.count += 1 def _dfs(self, v_start): stack = [v_start, 0] while(stack): v, id = stack[-2:] if(id == 0 and v in self.visited): stack.pop() stack.pop() continue self.visited.add(v) if(id < len(self.route[v])): stack[-1] += 1 stack.extend([self.route[v][id], 0]) continue stack.pop() self.v_list.append(stack.pop()) def _rev_dfs(self, v_start): stack = [v_start] self.label[v_start] = self.count while(stack): v_now = stack.pop() for v_next in self.rev_route[v_now]: if(self.label[v_next] != -1): continue self.label[v_next] = self.count stack.append(v_next) def construct(self): self._build() dag = [[] for _ in [0] * self.count] groups = [[] for _ in [0] * self.count] for v, lb in enumerate(self.label): for v_next in self.route[v]: lb_next = self.label[v_next] if(lb == lb_next): continue dag[lb].append(lb_next) groups[lb].append(v) return dag, groups """ Main Code """ N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [x - 1 for x in map(int, input().split())] scc = SCC(N) for i, x in enumerate(C): if(i == x): continue scc.add_edge(x, i) dag, groups = scc.construct() n = len(groups) a = [0] * n b = [0] * n for i, group in enumerate(groups): a[i] = sum(A[x] for x in group) b[i] = sum(B[x] for x in group) def check(mid): dp = [x - mid * y for x, y in zip(a, b)] visited = [0] * n def dfs(x): visited[x] = 1 dp[x] += sum(dfs(y) for y in dag[x]) return min(dp[x], 0) for v_start in range(n): if(visited[v_start] or dfs(v_start) == 0): continue return False return True ok = 0 ng = sum(a) // sum(b) + 1 while(abs(ok - ng) > 1): mid = (ok + ng) >> 1 if check(mid): ok = mid else: ng = mid print(ok)