結果

問題 No.1137 Circles
ユーザー yuruhiyayuruhiya
提出日時 2020-07-27 18:26:34
言語 Crystal
(1.11.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,025 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 218,844 KB
最終ジャッジ日時 2024-04-27 03:18:02
合計ジャッジ時間 3,404 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Showing last frame. Use --error-trace for full trace.

In Main.cr:27:9

 27 | add(*Indexable.range_to_index_and_count(range, size), val)
          ^
Error: splatting a union (Tuple(Int32, Int32) | Nil) is not yet supported

ソースコード

diff #

class Imos(T)
  @flag = false

  def initialize(@size : Int32)
    @a = Array(T).new(@size + 1, T.zero)
  end

  def initialize(@size : Int32, init_val : T)
    @a = Array(T).new(@size + 1, init_val)
  end

  getter size : Int32

  def add(start : Int, count : Int, val : T)
    raise "self had been called `build`" if @flag
    raise ArgumentError.new "Negative count: #{count}" if count < 0
    start += size if start < 0
    if 0 <= start <= size
      count = Math.min(count, size - start)
      @a[start] += val
      @a[start + count] -= val
    end
    nil
  end

  def add(range : Range, val : T)
    add(*Indexable.range_to_index_and_count(range, size), val)
  end

  def build
    raise "self had been called `build`" if @flag
    @flag = true
    (1..size).each do |i|
      @a[i] += @a[i - 1]
    end
    @a
  end
end

n = read_line.to_i
MAX_X = 2 * 10**5 + 5
imos = Imos(Int32).new(MAX_X * 2)
n.times do
  x, r = read_line.split.map &.to_i
  x += MAX_X
  imos.add(x - r...x + r, 1)
end
a = imos.build
puts a.max
0