結果

問題 No.5 数字のブロック
ユーザー asatakeasatake
提出日時 2018-08-12 12:07:10
言語 Elixir
(1.18.1)
結果
AC  
実行時間 598 ms / 5,000 ms
コード長 492 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 66,536 KB
実行使用メモリ 59,228 KB
最終ジャッジ日時 2024-12-31 02:14:08
合計ジャッジ時間 22,236 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
    warning: variable "c" is unused (if the variable is not meant to be used, prefix it with an underscore)
    │
 14 │   defp calc(c, [], l) do
    │             ~
    │
    └─ Main.exs:14:13: Main.calc/3

    warning: variable "l" is unused (if the variable is not meant to be used, prefix it with an underscore)
    │
 14 │   defp calc(c, [], l) do
    │                    ~
    │
    └─ Main.exs:14:20: Main.calc/3

ソースコード

diff #

defmodule Main do
  def main() do
    l = IO.gets("") |> String.trim |> String.to_integer
    n = IO.gets("") |> String.trim |> String.to_integer
    w = IO.gets("")
    |> String.trim
    |> String.split
    |> Enum.map(fn x -> String.to_integer(x) end)
    |> Enum.sort

    IO.inspect n - calc(0, w, l)
  end

  defp calc(c, [], l) do
    0
  end

  defp calc(c, w, l) do
    [h | t] = w
    cond do
      c + h <= l -> calc(c + h, t, l)
      true -> Enum.count(t) + 1
    end
  end

end
0