結果
問題 | No.10 +か×か |
ユーザー | penqen |
提出日時 | 2021-04-06 16:59:41 |
言語 | Elixir (1.16.2) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,365 bytes |
コンパイル時間 | 4,272 ms |
コンパイル使用メモリ | 61,916 KB |
実行使用メモリ | 55,860 KB |
最終ジャッジ日時 | 2024-05-08 12:04:29 |
合計ジャッジ時間 | 13,552 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 708 ms
54,192 KB |
testcase_01 | AC | 713 ms
53,804 KB |
testcase_02 | AC | 608 ms
53,804 KB |
testcase_03 | AC | 591 ms
55,860 KB |
testcase_04 | AC | 577 ms
54,484 KB |
testcase_05 | AC | 574 ms
54,188 KB |
testcase_06 | AC | 585 ms
55,600 KB |
testcase_07 | AC | 567 ms
54,200 KB |
testcase_08 | AC | 644 ms
54,276 KB |
testcase_09 | AC | 621 ms
53,968 KB |
testcase_10 | RE | - |
testcase_11 | AC | 633 ms
53,928 KB |
コンパイルメッセージ
warning: missing parentheses for expression following "do:" keyword. Parentheses are required to solve ambiguity inside keywords. This error happens when you have function calls without parentheses inside keywords. For example: function(arg, one: nested_call a, b, c) function(arg, one: if expr, do: :this, else: :that) In the examples above, we don't know if the arguments "b" and "c" apply to the function "function" or "nested_call". Or if the keywords "do" and "else" apply to the function "function" or "if". You can solve this by explicitly adding parentheses: function(arg, one: if(expr, do: :this, else: :that)) function(arg, one: nested_call(a, b, c)) Ambiguity found at: │ 19 │ do: if :math.fmod(rest, a) == 0, do: update(dp, div(rest, a), [Enum.max(wi)], ub), else: dp │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ │ └─ Main.exs:19 warning: use Bitwise is deprecated. import Bitwise instead │ 2 │ use Bitwise, only_operators: true │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ │ └─ Main.exs:2: Main (module)
ソースコード
defmodule Main do use Bitwise, only_operators: true def main do n = IO.read(:line) |> String.trim() |> String.to_integer() total = IO.read(:line) |> String.trim() |> String.to_integer() an = IO.read(:line) |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1) {_, ub} = Enum.reduce(0..(n - 1), {an, %{}}, fn i, {[a | an], ub} -> {an, Map.put(ub, i, Enum.reduce(an, a, &(:erlang.max(&1 * &2, &1 + &2))))} end) [a | an] = an an |> Enum.reverse() |> Enum.with_index() |> Enum.reduce(Map.put(%{}, total, [0]), fn {_a, i} = step, dp -> Enum.reduce(dp, %{}, &(&2 |> times(&1, step, ub[i]) |> plus(&1, step, ub[i]))) end) |> Map.get(a) |> Enum.max() |> restore(n) |> Enum.reverse() |> Enum.join("") |> IO.puts() end def times(dp, {rest, wi}, {a, _i}, ub), do: if :math.fmod(rest, a) == 0, do: update(dp, div(rest, a), [Enum.max(wi)], ub), else: dp def plus(dp, {rest, wi}, {a, i}, ub) when a <= rest, do: update(dp, rest - a, Enum.map(wi, fn w -> w + (1 <<< i) end), ub) def plus(dp, {_rest, _wi}, {_a, _i}, _ub), do: dp def update(dp, key, wi, ub) when key <= ub, do: Map.update(dp, key, wi, fn q -> wi ++ q end) def update(dp, _key, _wi, _ub), do: dp def restore(_w, 1), do: [] def restore(w, i), do: [(if (w &&& 1) == 1, do: :+, else: :*) | restore(w >>> 1 ,i - 1)] end