結果

問題 No.1869 Doubling?
ユーザー simansiman
提出日時 2022-03-13 01:36:31
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 429 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 11,792 KB
実行使用メモリ 15,976 KB
最終ジャッジ日時 2023-10-17 12:08:39
合計ジャッジ時間 6,152 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,976 KB
testcase_01 AC 85 ms
15,976 KB
testcase_02 AC 86 ms
15,976 KB
testcase_03 AC 88 ms
15,976 KB
testcase_04 AC 85 ms
15,976 KB
testcase_05 AC 86 ms
15,976 KB
testcase_06 AC 86 ms
15,972 KB
testcase_07 AC 83 ms
15,976 KB
testcase_08 AC 84 ms
15,976 KB
testcase_09 WA -
testcase_10 AC 85 ms
15,976 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 85 ms
15,976 KB
testcase_16 AC 85 ms
15,976 KB
testcase_17 AC 85 ms
15,972 KB
testcase_18 AC 86 ms
15,976 KB
testcase_19 AC 84 ms
15,968 KB
testcase_20 AC 86 ms
15,976 KB
testcase_21 AC 86 ms
15,972 KB
testcase_22 AC 86 ms
15,976 KB
testcase_23 AC 86 ms
15,976 KB
testcase_24 AC 86 ms
15,976 KB
testcase_25 AC 84 ms
15,976 KB
testcase_26 AC 85 ms
15,976 KB
testcase_27 AC 86 ms
15,976 KB
testcase_28 AC 85 ms
15,976 KB
testcase_29 AC 85 ms
15,976 KB
testcase_30 AC 85 ms
15,976 KB
testcase_31 AC 85 ms
15,976 KB
testcase_32 AC 86 ms
15,976 KB
testcase_33 AC 85 ms
15,976 KB
testcase_34 AC 86 ms
15,972 KB
testcase_35 AC 87 ms
15,976 KB
testcase_36 AC 86 ms
15,976 KB
testcase_37 AC 86 ms
15,976 KB
testcase_38 AC 83 ms
15,976 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 85 ms
15,976 KB
testcase_43 AC 87 ms
15,976 KB
testcase_44 AC 87 ms
15,976 KB
testcase_45 AC 87 ms
15,976 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)

def f(x)
  sum = 1
  m = x
  remain = N

  while remain > 1 && m > 1
    sum += m

    if Math.log2(m).ceil < remain
      m = (m + 1) / 2
    else
      m = m / 2
    end

    remain -= 1
  end

  if m != 1
    -1
  else
    sum + remain - 1
  end
end

ok = 1
ng = M + 1

while (ok - ng).abs >= 2
  x = (ok + ng) / 2
  val = f(x)

  if val != -1
    ok = x
  else
    ng = x
  end
end

puts f(ok)
0