結果
問題 |
No.3292 World Map Distance
|
ユーザー |
![]() |
提出日時 | 2025-09-13 02:35:17 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 1,416 ms / 3,000 ms |
コード長 | 1,341 bytes |
コンパイル時間 | 346 ms |
コンパイル使用メモリ | 8,320 KB |
実行使用メモリ | 77,740 KB |
最終ジャッジ日時 | 2025-09-13 02:35:43 |
合計ジャッジ時間 | 25,132 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
コンパイルメッセージ
Main.rb:45: warning: assigned but unused variable - left Syntax OK
ソースコード
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 def solve(n,a,l) a.map!{|v| v-1 } a.sort! kouho = a.dup a.each do |v| if l%2 == 0 kouho << (v + l/2)%l else kouho << (v + l/2)%l kouho << (v + 1 + l/2)%l end end kouho.uniq! kouho.sort! stack_left = [] stack_right = [] now = 0 i = 0 while i < n && a[i] <= l/2 stack_right << a[i] now += a[i] i += 1 end while i < n stack_left << a[i] - l now += l-a[i] i += 1 end max = now kouho_len = kouho.length i = 0 pre = 0 while i < kouho_len pos = kouho[i] right = pos + (l-1)/2 left = pos - l/2 sub_cnt_left = stack_left.size sub_cnt_right = stack_right.size while stack_left.empty?.! && stack_left[0]+l <= right v = stack_left.shift now -= pre - v stack_right << v + l now += v + l - pos sub_cnt_left -= 1 end now += sub_cnt_left * (pos - pre) while stack_right.empty?.! && stack_right[0] <= pos v = stack_right.shift now -= v - pre stack_left << v now += pos - v sub_cnt_right -= 1 end now -= sub_cnt_right * (pos - pre) max = now if max < now pre = pos i += 1 end max end ans = solve(n,xs,X) + solve(n,ys,Y) puts ans