結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | rlangevin |
提出日時 | 2023-03-22 12:50:42 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,065 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 213,828 KB |
最終ジャッジ日時 | 2024-09-18 14:52:01 |
合計ジャッジ時間 | 12,618 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,144 KB |
testcase_01 | AC | 46 ms
54,784 KB |
testcase_02 | AC | 45 ms
54,912 KB |
testcase_03 | AC | 398 ms
191,228 KB |
testcase_04 | WA | - |
testcase_05 | AC | 47 ms
55,040 KB |
testcase_06 | AC | 317 ms
164,448 KB |
testcase_07 | AC | 417 ms
213,828 KB |
testcase_08 | AC | 486 ms
209,636 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 478 ms
208,024 KB |
testcase_12 | AC | 480 ms
179,348 KB |
testcase_13 | AC | 539 ms
174,200 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 339 ms
174,084 KB |
testcase_17 | AC | 45 ms
54,400 KB |
testcase_18 | AC | 552 ms
184,172 KB |
testcase_19 | WA | - |
testcase_20 | AC | 440 ms
186,896 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
ソースコード
from collections import * import sys sys.setrecursionlimit(10**7) from heapq import * def topsort(G): Q = [] count = dict((u, 0) for u in range(len(G))) for u in range(len(G)): for v in G[u]: count[v] += 1 temp = [] for u in range(len(G)): if count[u] == 0: heappush(Q, u) anslst = [] while Q: u = heappop(Q) anslst.append(u) temp = [] for v in G[u]: count[v] -= 1 if count[v] == 0: heappush(Q, v) anslst.reverse() return anslst class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N = int(input()) X = list(map(int, input().split())) A = list(map(int, input().split())) D = defaultdict(lambda:-1) for i in range(N): D[X[i]] = i T = UnionFind(N) G = [[] for i in range(N)] for i in range(N): if D[X[i] + A[i]] != -1: T.union(i, D[X[i] + A[i]]) G[i].append(D[X[i] + A[i]]) for i in range(N): if D[X[i] - A[i]] != -1: if not T.is_same(i, D[X[i] - A[i]]): G[i].append(D[X[i] - A[i]]) B = topsort(G) M = [0] * N for i in range(N): M[i] = X[i] + A[i] for b in B: for u in G[b]: M[b] = max(M[u], X[b] + A[b]) for i in range(N): print(M[i] - X[i])