結果

問題 No.989 N×Mマス計算(K以上)
ユーザー le_panda_noirle_panda_noir
提出日時 2020-02-20 11:56:08
言語 Elixir
(1.16.2)
結果
AC  
実行時間 1,311 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 1,222 ms
コンパイル使用メモリ 55,748 KB
実行使用メモリ 92,932 KB
最終ジャッジ日時 2023-08-29 23:50:18
合計ジャッジ時間 19,268 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 617 ms
49,312 KB
testcase_01 AC 618 ms
49,108 KB
testcase_02 AC 620 ms
49,184 KB
testcase_03 AC 642 ms
49,256 KB
testcase_04 AC 624 ms
49,128 KB
testcase_05 AC 631 ms
49,456 KB
testcase_06 AC 647 ms
49,204 KB
testcase_07 AC 629 ms
49,468 KB
testcase_08 AC 631 ms
49,480 KB
testcase_09 AC 625 ms
49,140 KB
testcase_10 AC 1,026 ms
70,844 KB
testcase_11 AC 917 ms
81,460 KB
testcase_12 AC 1,086 ms
77,572 KB
testcase_13 AC 751 ms
77,612 KB
testcase_14 AC 1,311 ms
92,932 KB
testcase_15 AC 819 ms
58,692 KB
testcase_16 AC 1,030 ms
64,188 KB
testcase_17 AC 750 ms
76,140 KB
testcase_18 AC 921 ms
55,168 KB
testcase_19 AC 884 ms
80,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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