結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-06 16:59:41 |
| 言語 | Elixir (1.18.1) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 RE * 1 |
コンパイルメッセージ
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