結果

問題 No.1869 Doubling?
ユーザー ID 21712
提出日時 2025-06-09 22:34:06
言語 Go
(1.23.4)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 372 bytes
コンパイル時間 12,103 ms
コンパイル使用メモリ 240,380 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-09 22:34:21
合計ジャッジ時間 13,884 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import . "fmt"


func main() {
	var n, m int
	Scan(&n,&m)
	
	ans := 0
	x := 0
	for i := 30; i >= 0; i-- {
		t := x + (1<<i)
		if t > m {
			continue
		}
		s, c := 0, 0
		for t > 1 {
			s += t
			c++
			if t % 2 == 0 {
				t /= 2
			} else {
				t = (t+1)/2
			}
		}
		if n - c < 1 {
			continue
		}
		x = x + (1<<i)
		ans = max(ans, s+n-c)
	}
	Println(ans)
}
0