結果
問題 | No.10 +か×か |
ユーザー | penqen |
提出日時 | 2021-04-06 16:59:41 |
言語 | Elixir (1.16.2) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,365 bytes |
コンパイル時間 | 5,333 ms |
コンパイル使用メモリ | 62,484 KB |
実行使用メモリ | 56,240 KB |
最終ジャッジ日時 | 2024-12-14 15:48:08 |
合計ジャッジ時間 | 12,698 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 535 ms
53,940 KB |
testcase_01 | AC | 541 ms
53,940 KB |
testcase_02 | AC | 547 ms
53,944 KB |
testcase_03 | AC | 571 ms
56,240 KB |
testcase_04 | AC | 556 ms
54,576 KB |
testcase_05 | AC | 547 ms
54,012 KB |
testcase_06 | AC | 560 ms
55,984 KB |
testcase_07 | AC | 549 ms
54,076 KB |
testcase_08 | AC | 551 ms
54,412 KB |
testcase_09 | AC | 552 ms
54,684 KB |
testcase_10 | RE | - |
testcase_11 | AC | 548 ms
54,544 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