結果
問題 |
No.1869 Doubling?
|
ユーザー |
![]() |
提出日時 | 2022-03-13 01:34:41 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 408 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 7,680 KB |
実行使用メモリ | 19,232 KB |
最終ジャッジ日時 | 2024-09-17 10:17:51 |
合計ジャッジ時間 | 4,120 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | TLE * 1 -- * 42 |
コンパイルメッセージ
Syntax OK
ソースコード
N, M = gets.split.map(&:to_i) def f(x) sum = 1 m = x remain = N while remain > 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 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)