結果

問題 No.1950 片道きゃっちぼーる
ユーザー simansiman
提出日時 2022-05-28 01:34:46
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,670 ms / 3,000 ms
コード長 500 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 11,868 KB
実行使用メモリ 169,820 KB
最終ジャッジ日時 2023-10-20 22:11:38
合計ジャッジ時間 24,865 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
16,028 KB
testcase_01 AC 76 ms
16,028 KB
testcase_02 AC 76 ms
16,028 KB
testcase_03 AC 1,153 ms
109,864 KB
testcase_04 AC 1,168 ms
109,864 KB
testcase_05 AC 76 ms
16,028 KB
testcase_06 AC 771 ms
70,788 KB
testcase_07 AC 1,488 ms
147,288 KB
testcase_08 AC 1,670 ms
169,820 KB
testcase_09 AC 1,224 ms
115,780 KB
testcase_10 AC 1,088 ms
114,084 KB
testcase_11 AC 1,049 ms
116,020 KB
testcase_12 AC 1,045 ms
117,184 KB
testcase_13 AC 940 ms
99,036 KB
testcase_14 AC 830 ms
74,316 KB
testcase_15 AC 1,349 ms
110,740 KB
testcase_16 AC 795 ms
71,180 KB
testcase_17 AC 76 ms
16,028 KB
testcase_18 AC 1,329 ms
122,320 KB
testcase_19 AC 1,341 ms
110,736 KB
testcase_20 AC 1,027 ms
116,024 KB
testcase_21 AC 916 ms
77,884 KB
testcase_22 AC 893 ms
77,888 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
X = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = [] }

max_v = Hash.new(0)

N.times do |i|
  x = X[i]
  a = A[i]

  E[x - a] << x
  E[x + a] << x
end

visited = Hash.new(false)

E.keys.sort.reverse_each do |cv|
  queue = []
  queue << cv

  until queue.empty?
    v = queue.shift

    next if visited[v]
    visited[v] = true

    max_v[v] = cv if max_v[v] < cv

    E[v].each do |u|
      queue << u
    end
  end
end

puts X.map { |x| max_v[x] - x }
0