結果

問題 No.3292 World Map Distance
ユーザー kona0001
提出日時 2025-09-25 02:51:06
言語 Ruby
(3.4.1)
結果
AC  
実行時間 1,379 ms / 3,000 ms
コード長 1,134 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 8,192 KB
実行使用メモリ 120,172 KB
最終ジャッジ日時 2025-09-25 02:51:37
合計ジャッジ時間 23,529 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def solve(n,a,l)
  a.map!{|v| v-1 }
  a.sort!
  kouho = a.dup
  kouho << 0
  now_slope = 0
  now_dist = 0
  slope_dif = Hash.new(0)
  a.each do |v|
    if l%2 == 0
      opposite = (v + l/2)%l
      kouho << opposite
      slope_dif[v] += 2
      slope_dif[opposite] -= 2
      now_dist += [v,l-v].min
      if v < l/2
        now_slope -= 1
      else
        now_slope += 1
      end
    else
      opposite_l = (v + l/2)%l
      opposite_r = (v + 1 + l/2)%l
      kouho << opposite_l
      kouho << opposite_r
      slope_dif[v] += 2
      slope_dif[opposite_l] -= 1
      slope_dif[opposite_r] -= 1
      now_dist += [v,l-v].min
      if v < l/2
        now_slope -= 1
      elsif v == l/2
        # nothing to do
      else
        now_slope += 1
      end
    end
  end
  kouho.uniq!
  kouho.sort!
  max = now_dist
  pre = 0
  kouho.each do |v|
    now_dist += (v-pre) * now_slope
    max = [max, now_dist].max
    now_slope += slope_dif[v]
    pre = v
  end
  max
end

n,X,Y = gets.split.map(&:to_i)
xs = []
ys = []
n.times do
  x,y = gets.split.map(&:to_i)
  xs << x
  ys << y
end

ans = solve(n,xs,X) + solve(n,ys,Y)
puts ans
0