結果

問題 No.648  お や す み 
ユーザー wotsushiwotsushi
提出日時 2018-07-30 20:09:21
言語 Elixir
(1.16.2)
結果
AC  
実行時間 701 ms / 2,000 ms
コード長 442 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 53,712 KB
実行使用メモリ 50,336 KB
最終ジャッジ日時 2023-08-29 22:54:59
合計ジャッジ時間 61,443 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 701 ms
49,312 KB
testcase_01 AC 661 ms
49,144 KB
testcase_02 AC 661 ms
49,292 KB
testcase_03 AC 657 ms
49,864 KB
testcase_04 AC 659 ms
49,152 KB
testcase_05 AC 654 ms
49,188 KB
testcase_06 AC 655 ms
49,152 KB
testcase_07 AC 650 ms
49,112 KB
testcase_08 AC 643 ms
49,324 KB
testcase_09 AC 663 ms
49,928 KB
testcase_10 AC 654 ms
49,344 KB
testcase_11 AC 657 ms
49,312 KB
testcase_12 AC 665 ms
49,308 KB
testcase_13 AC 650 ms
49,812 KB
testcase_14 AC 646 ms
49,884 KB
testcase_15 AC 665 ms
50,092 KB
testcase_16 AC 665 ms
49,052 KB
testcase_17 AC 653 ms
49,280 KB
testcase_18 AC 663 ms
49,160 KB
testcase_19 AC 641 ms
49,756 KB
testcase_20 AC 665 ms
50,336 KB
testcase_21 AC 663 ms
49,188 KB
testcase_22 AC 648 ms
49,336 KB
testcase_23 AC 664 ms
49,072 KB
testcase_24 AC 657 ms
49,180 KB
testcase_25 AC 656 ms
49,728 KB
testcase_26 AC 653 ms
49,844 KB
testcase_27 AC 659 ms
49,352 KB
testcase_28 AC 652 ms
49,380 KB
testcase_29 AC 656 ms
49,308 KB
testcase_30 AC 648 ms
49,816 KB
testcase_31 AC 655 ms
49,252 KB
testcase_32 AC 640 ms
50,012 KB
testcase_33 AC 653 ms
49,288 KB
testcase_34 AC 663 ms
49,360 KB
testcase_35 AC 647 ms
49,356 KB
testcase_36 AC 663 ms
49,868 KB
testcase_37 AC 654 ms
49,068 KB
testcase_38 AC 657 ms
49,008 KB
testcase_39 AC 666 ms
49,128 KB
testcase_40 AC 648 ms
50,252 KB
testcase_41 AC 660 ms
50,212 KB
testcase_42 AC 672 ms
49,440 KB
testcase_43 AC 651 ms
49,244 KB
testcase_44 AC 641 ms
49,304 KB
testcase_45 AC 672 ms
49,812 KB
testcase_46 AC 667 ms
49,448 KB
testcase_47 AC 658 ms
49,916 KB
testcase_48 AC 667 ms
49,052 KB
testcase_49 AC 666 ms
49,104 KB
testcase_50 AC 668 ms
49,064 KB
testcase_51 AC 664 ms
50,096 KB
testcase_52 AC 652 ms
49,280 KB
testcase_53 AC 661 ms
49,452 KB
testcase_54 AC 654 ms
49,216 KB
testcase_55 AC 658 ms
50,044 KB
testcase_56 AC 672 ms
50,016 KB
testcase_57 AC 664 ms
49,208 KB
testcase_58 AC 668 ms
49,176 KB
testcase_59 AC 651 ms
49,408 KB
testcase_60 AC 655 ms
50,136 KB
testcase_61 AC 662 ms
49,316 KB
testcase_62 AC 647 ms
49,660 KB
testcase_63 AC 650 ms
49,216 KB
testcase_64 AC 657 ms
50,264 KB
testcase_65 AC 641 ms
49,116 KB
testcase_66 AC 665 ms
49,808 KB
testcase_67 AC 648 ms
50,052 KB
testcase_68 AC 646 ms
49,672 KB
testcase_69 AC 656 ms
49,104 KB
testcase_70 AC 656 ms
49,236 KB
testcase_71 AC 668 ms
49,264 KB
testcase_72 AC 659 ms
49,104 KB
testcase_73 AC 656 ms
49,836 KB
testcase_74 AC 668 ms
49,308 KB
testcase_75 AC 653 ms
49,092 KB
testcase_76 AC 659 ms
49,148 KB
testcase_77 AC 658 ms
49,192 KB
testcase_78 AC 652 ms
50,312 KB
testcase_79 AC 660 ms
49,224 KB
testcase_80 AC 655 ms
50,024 KB
testcase_81 AC 659 ms
49,276 KB
testcase_82 AC 676 ms
49,200 KB
testcase_83 AC 656 ms
49,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  defp bis(_, l, h) when l > h, do: :ng
  defp bis(n, l, h) do
    x = div(h + l, 2)
    s = div(x * (x + 1), 2)
    cond do
      s < n
        -> bis(n, x + 1, h)
      s == n
        -> x
      s > n
        -> bis(n, l, x - 1)
    end
  end

  def main do
    n = IO.gets("") |> String.trim |> String.to_integer

    ans = case bis(n, 1, n) do
      :ng -> "NO"
      m -> "YES\n#{m}"
    end

    IO.puts ans
  end
end
0