結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | rlangevin |
提出日時 | 2023-06-05 22:35:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 964 bytes |
コンパイル時間 | 1,434 ms |
コンパイル使用メモリ | 86,656 KB |
実行使用メモリ | 163,576 KB |
最終ジャッジ日時 | 2023-08-28 09:45:22 |
合計ジャッジ時間 | 10,648 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
71,560 KB |
testcase_01 | AC | 88 ms
71,524 KB |
testcase_02 | AC | 89 ms
71,412 KB |
testcase_03 | AC | 383 ms
163,116 KB |
testcase_04 | AC | 513 ms
163,576 KB |
testcase_05 | AC | 89 ms
71,208 KB |
testcase_06 | AC | 306 ms
156,852 KB |
testcase_07 | TLE | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
ソースコード
from collections import * def bfs(G, s, N): Q = deque([]) dist = [-1] * N dist[s] = 0 for u in G[s]: dist[u] = 1 seen[u] = seen[s] Q.append(u) while Q: u = Q.popleft() for v in G[u]: if seen[v] != -1: continue dist[v] = dist[u] + 1 seen[v] = seen[u] Q.append(v) return dist N = int(input()) X = list(map(int, input().split())) A = list(map(int, input().split())) G = [[] for i in range(N)] D = defaultdict(int) for i in range(N): D[X[i]] = i for i in range(N): if X[i] + A[i] in D: G[D[X[i] + A[i]]].append(i) if X[i] - A[i] in D: G[D[X[i] - A[i]]].append(i) seen = [-1] * N L = [] for i in range(N): L.append((X[i] + A[i], i)) L.sort(reverse=True) for d, i in L: if seen[i] != -1: continue seen[i] = d bfs(G, i, N) for i in range(N): print(seen[i] - X[i])