結果

問題 No.1033 乱数サイ
ユーザー penqenpenqen
提出日時 2020-12-16 15:18:11
言語 Elixir
(1.16.2)
結果
AC  
実行時間 691 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 55,924 KB
実行使用メモリ 50,408 KB
最終ジャッジ日時 2023-08-30 01:12:34
合計ジャッジ時間 13,808 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 618 ms
49,724 KB
testcase_01 AC 618 ms
49,488 KB
testcase_02 AC 615 ms
50,100 KB
testcase_03 AC 618 ms
49,548 KB
testcase_04 AC 626 ms
50,004 KB
testcase_05 AC 624 ms
49,640 KB
testcase_06 AC 631 ms
50,132 KB
testcase_07 AC 627 ms
50,232 KB
testcase_08 AC 626 ms
49,520 KB
testcase_09 AC 615 ms
50,200 KB
testcase_10 AC 622 ms
49,500 KB
testcase_11 AC 618 ms
49,584 KB
testcase_12 AC 632 ms
49,368 KB
testcase_13 AC 633 ms
50,316 KB
testcase_14 AC 644 ms
49,532 KB
testcase_15 AC 668 ms
50,408 KB
testcase_16 AC 691 ms
49,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  def main do
    [n, k] = IO.read(:line) |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)
    solve(n, k) |> IO.puts()
  end

  def solve(n, k) when 1 <= n and n <= 100_000
    and 1 <= k and k <= 100_000
  do
    0..n
    |> Enum.reduce({0, 0}, fn ni, {sum, count} ->
      ki = 0..k |> Enum.count
      {sum + ni * ki, count + ki}
    end)
    |> (fn {sum, count} ->
      sum / count
    end).()
  end
end
0