結果

問題 No.1950 片道きゃっちぼーる
ユーザー qibqib
提出日時 2022-11-28 00:01:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 818 ms / 3,000 ms
コード長 876 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,076 KB
実行使用メモリ 263,396 KB
最終ジャッジ日時 2024-04-15 04:39:06
合計ジャッジ時間 12,491 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,660 KB
testcase_01 AC 38 ms
54,028 KB
testcase_02 AC 37 ms
53,252 KB
testcase_03 AC 486 ms
263,396 KB
testcase_04 AC 477 ms
257,448 KB
testcase_05 AC 34 ms
54,100 KB
testcase_06 AC 249 ms
193,716 KB
testcase_07 AC 416 ms
240,088 KB
testcase_08 AC 818 ms
250,088 KB
testcase_09 AC 456 ms
253,368 KB
testcase_10 AC 503 ms
223,700 KB
testcase_11 AC 473 ms
221,628 KB
testcase_12 AC 474 ms
221,152 KB
testcase_13 AC 356 ms
212,104 KB
testcase_14 AC 318 ms
194,948 KB
testcase_15 AC 760 ms
224,696 KB
testcase_16 AC 265 ms
187,980 KB
testcase_17 AC 34 ms
53,116 KB
testcase_18 AC 544 ms
260,224 KB
testcase_19 AC 759 ms
224,324 KB
testcase_20 AC 466 ms
223,536 KB
testcase_21 AC 350 ms
222,696 KB
testcase_22 AC 350 ms
222,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 1 << 60

n = int(input())
x = list(map(int, input().split()))
a = list(map(int, input().split()))

s = set()
for i in range(n):
  s.add(x[i])
  s.add(x[i] - a[i])
  s.add(x[i] + a[i])

xs = sorted(list(s))
idx = {}
for i in range(len(xs)):
  idx[xs[i]] = i

g = [[] for _ in range(len(xs))]
deg = [0 for _ in range(len(xs))]
for i in range(n):
  v = idx[x[i]]
  u = idx[x[i] - a[i]]
  w = idx[x[i] + a[i]]
  g[w].append(v)
  g[u].append(v)
  deg[v] += 1
  deg[v] += 1

dist = [INF for _ in range(len(xs))]
par = [None for _ in range(len(xs))]
st = []
for v in range(len(xs)):
  if deg[v] == 0:
    dist[v] = 0
    par[v] = v
    st.append(v)

while len(st) > 0:
  cur = st.pop()
  for nxt in g[cur]:
    if not par[nxt] is None:
      continue
    par[nxt] = par[cur]
    dist[nxt] = xs[par[nxt]] - xs[nxt]
    st.append(nxt)

for i in range(n):
  print(dist[idx[x[i]]])
0