結果

問題 No.989 N×Mマス計算(K以上)
コンテスト
ユーザー le_panda_noir
提出日時 2020-02-20 11:56:08
言語 Elixir
(1.19.5)
コンパイル:
elixirc _filename_
実行:
elixir -e Main.main
結果
AC  
実行時間 1,176 ms / 2,000 ms
コード長 911 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 632 ms
コンパイル使用メモリ 73,456 KB
実行使用メモリ 140,416 KB
最終ジャッジ日時 2026-06-04 14:51:07
合計ジャッジ時間 13,279 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

defmodule Main do
  def lower_bound(list, val, l \\ -1, r \\ -1) do
    if r == -1 do
      lower_bound(list, val, l, map_size(list))
    else
      m = div(l + r, 2)
      if (r - l) <= 1 do
        r
      else
        cond do
          list[m] < val -> lower_bound(list, val, m, r)
          list[m] >= val -> lower_bound(list, val, l, m)
        end
      end
    end
  end
  def main do
    toi = &String.to_integer/1
    split = &String.split/1

    [n, _m, k] = IO.gets("") |> split.() |> Enum.map(toi)
    [op | b] = IO.gets("") |> split.()
    b = Enum.map(b, toi) |> Enum.sort |> Enum.with_index |> Enum.reduce(%{}, fn({x, index}, acc) -> Map.put(acc, index, x) end)

    Enum.map(1..n, fn _ ->
      a = IO.gets("") |> String.trim |> toi.()
      if op == "+", do: map_size(b) - lower_bound(b, k-a),
      else: map_size(b) - lower_bound(b, Float.ceil(k/a))
    end) |> Enum.sum |> IO.puts
  end
end
0