結果

問題 No.5 数字のブロック
コンテスト
ユーザー asatake
提出日時 2018-08-12 11:57:09
言語 Elixir
(1.19.5)
コンパイル:
elixirc _filename_
実行:
elixir -e Main.main
結果
WA  
実行時間 -
コード長 518 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 935 ms
コンパイル使用メモリ 72,968 KB
実行使用メモリ 67,780 KB
最終ジャッジ日時 2026-06-04 13:35:59
合計ジャッジ時間 13,891 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
    warning: the result of evaluating operator '+'/2 is ignored (suppress the warning by assigning the expression to the _ variable)
    │
 20 │         true -> Enum.count(t) + 1
    │                               ~
    │
    └─ Main.exs:20:31

ソースコード

diff #
raw source code

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, w, l) do
    if Enum.count(w) > 0 do
      h = hd w
      t = tl w
      cond do
        c + h <= l -> calc(c + h, t, l)
        true -> Enum.count(t) + 1
      end
    end
    0
  end

end
0