結果

問題 No.1869 Doubling?
ユーザー ks2m
提出日時 2022-03-11 22:25:56
言語 Java
(openjdk 23)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 2,883 ms
コンパイル使用メモリ 74,652 KB
実行使用メモリ 41,284 KB
最終ジャッジ日時 2024-09-16 02:47:57
合計ジャッジ時間 9,850 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		if (n < 32 && 1 << (n - 1) < m) {
			long ans = 0;
			for (int i = 0; i < n; i++) {
				ans += 1 << i;
			}
			System.out.println(ans);
		} else {
			int p = m;
			long ans = m;
			for (int i = 1; i < n; i++) {
				if (p == 1) {
					ans += n - i;
					break;
				}
				if (p % 2 == 0) {
					p = p / 2;
				} else {
					p = p / 2 + 1;
				}
				ans += p;
			}
			System.out.println(ans);
		}
	}
}
0