結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | 👑 rin204 |
提出日時 | 2022-05-20 22:09:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 570 ms / 3,000 ms |
コード長 | 2,192 bytes |
コンパイル時間 | 171 ms |
コンパイル使用メモリ | 81,896 KB |
実行使用メモリ | 202,464 KB |
最終ジャッジ日時 | 2024-09-20 08:19:51 |
合計ジャッジ時間 | 10,785 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
53,160 KB |
testcase_01 | AC | 37 ms
52,336 KB |
testcase_02 | AC | 37 ms
52,776 KB |
testcase_03 | AC | 431 ms
202,464 KB |
testcase_04 | AC | 439 ms
201,536 KB |
testcase_05 | AC | 38 ms
54,396 KB |
testcase_06 | AC | 325 ms
174,584 KB |
testcase_07 | AC | 324 ms
168,028 KB |
testcase_08 | AC | 337 ms
167,916 KB |
testcase_09 | AC | 374 ms
172,904 KB |
testcase_10 | AC | 426 ms
186,836 KB |
testcase_11 | AC | 399 ms
187,640 KB |
testcase_12 | AC | 411 ms
187,552 KB |
testcase_13 | AC | 481 ms
178,252 KB |
testcase_14 | AC | 378 ms
150,688 KB |
testcase_15 | AC | 570 ms
169,272 KB |
testcase_16 | AC | 333 ms
157,880 KB |
testcase_17 | AC | 38 ms
53,296 KB |
testcase_18 | AC | 434 ms
178,172 KB |
testcase_19 | AC | 550 ms
168,224 KB |
testcase_20 | AC | 336 ms
168,080 KB |
testcase_21 | AC | 391 ms
169,888 KB |
testcase_22 | AC | 375 ms
169,628 KB |
ソースコード
def scc(N, G): order = [] used = [False]*N group = [None]*N RG = [[] for _ in range(N)] for i in range(N): for j in G[i]: RG[j].append(i) def dfs(pos): stack = [(1, pos), (0, pos)] while stack: t, pos = stack.pop() if t == 0: if used[pos]: stack.pop() continue used[pos] = True for npos in G[pos]: if not used[npos]: stack.append((1, npos)) stack.append((0, npos)) else: order.append(pos) def rdfs(pos, col): stack = [pos] group[pos] = col used[pos] = True while stack: pos = stack.pop() for npos in RG[pos]: if not used[npos]: used[npos] = True group[npos] = col stack.append(npos) for i in range(N): if not used[i]: dfs(i) used = [False]*N label = 0 for s in reversed(order): if not used[s]: rdfs(s, label) label += 1 return label, group def construct(N, G, label, group): G0 = [[] for _ in range(label)] GP = [[] for _ in range(label)] for v in range(N): lbs = group[v] for w in G[v]: lbt = group[w] if lbs == lbt: continue G0[lbs].append(lbt) GP[lbs].append(v) return G0, GP n = int(input()) X = list(map(int, input().split())) A = list(map(int, input().split())) dic = {} for i, x in enumerate(X): dic[x] = i edges = [[] for _ in range(n)] for i in range(n): if X[i] - A[i] in dic: edges[i].append(dic[X[i] - A[i]]) if X[i] + A[i] in dic: edges[i].append(dic[X[i] + A[i]]) label, group = scc(n, edges) g0, gp = construct(n, edges, label, group) dp = [0] * label for i in range(label - 1, -1, -1): for j in gp[i]: dp[i] = max(dp[i], A[j] + X[j]) for j in g0[i]: dp[i] = max(dp[i], dp[j]) for i in range(n): print(dp[group[i]] - X[i])