結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | gr1msl3y |
提出日時 | 2022-05-22 23:11:25 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,021 bytes |
コンパイル時間 | 312 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 233,276 KB |
最終ジャッジ日時 | 2024-09-20 12:57:20 |
合計ジャッジ時間 | 13,358 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
54,016 KB |
testcase_01 | AC | 43 ms
54,656 KB |
testcase_02 | AC | 42 ms
54,144 KB |
testcase_03 | AC | 596 ms
230,188 KB |
testcase_04 | WA | - |
testcase_05 | AC | 42 ms
54,656 KB |
testcase_06 | AC | 487 ms
208,844 KB |
testcase_07 | AC | 489 ms
199,040 KB |
testcase_08 | AC | 508 ms
203,476 KB |
testcase_09 | AC | 522 ms
224,272 KB |
testcase_10 | AC | 577 ms
230,716 KB |
testcase_11 | AC | 563 ms
228,792 KB |
testcase_12 | AC | 570 ms
228,144 KB |
testcase_13 | AC | 663 ms
225,172 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 547 ms
205,004 KB |
testcase_17 | AC | 44 ms
54,656 KB |
testcase_18 | AC | 663 ms
224,692 KB |
testcase_19 | WA | - |
testcase_20 | AC | 496 ms
204,340 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
ソースコード
from collections import defaultdict, deque from bisect import bisect_left N = int(input()) X = [-10**9]+list(map(int, input().split())) A = [0]+list(map(int, input().split())) graph = defaultdict(list) graph_inv = defaultdict(list) for i in range(N+1): x = X[i] a = A[i] ind = bisect_left(X, x-a) if X[ind] == x-a: graph[i].append(ind) graph_inv[ind].append(i) ind = bisect_left(X, x+a) if ind <= N and X[ind] == x+a: graph[i].append(ind) graph_inv[ind].append(i) def scc(N, G, RG): order = [] seen = [0]*N group = [None]*N def dfs(s): task = deque([(s, 1), (s, 0)]) while task: v, t = task.pop() if t: if seen[v] == 2: continue seen[v] = 2 order.append(v) else: if seen[v]: continue seen[v] = 1 for e in G[v]: if not seen[e]: task.append((e, 1)) task.append((e, 0)) def rdfs(s, col): task = deque([s]) while task: v = task.pop() if seen[v]: continue seen[v] = 1 group[v] = col for e in RG[v]: if not seen[e]: task.append(e) for i in range(N): if not seen[i]: dfs(i) seen = [0]*N label = 0 for s in reversed(order): if not seen[s]: rdfs(s, label) label += 1 return label, group n, L = scc(N+1, graph, graph_inv) Y = [[] for _ in range(n)] for i in range(N+1): Y[L[i]].append(i) ans = [0]*(N+1) for i in range(n-1, -1, -1): ind = Y[i][-1] ans[ind] = A[ind] for u in graph[ind]: if L[u] == i: continue ans[ind] = max(ans[ind], X[u]+ans[u]-X[ind]) for v in Y[i][:-1]: ans[v] = X[ind]+ans[ind]-X[v] print(*ans[1:], sep='\n')