結果

問題 No.1869 Doubling?
ユーザー ks2mks2m
提出日時 2022-03-11 22:25:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 1,987 ms
コンパイル使用メモリ 72,464 KB
実行使用メモリ 56,668 KB
最終ジャッジ日時 2023-10-14 07:40:21
合計ジャッジ時間 9,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,184 KB
testcase_01 AC 121 ms
56,020 KB
testcase_02 AC 121 ms
56,668 KB
testcase_03 AC 122 ms
56,404 KB
testcase_04 AC 121 ms
56,092 KB
testcase_05 AC 122 ms
55,964 KB
testcase_06 AC 121 ms
56,160 KB
testcase_07 AC 122 ms
55,892 KB
testcase_08 AC 119 ms
55,992 KB
testcase_09 AC 122 ms
55,992 KB
testcase_10 AC 122 ms
54,236 KB
testcase_11 AC 118 ms
56,120 KB
testcase_12 AC 118 ms
56,576 KB
testcase_13 AC 120 ms
56,464 KB
testcase_14 AC 121 ms
55,612 KB
testcase_15 AC 123 ms
55,736 KB
testcase_16 AC 122 ms
56,104 KB
testcase_17 AC 122 ms
55,532 KB
testcase_18 AC 121 ms
56,324 KB
testcase_19 AC 124 ms
56,308 KB
testcase_20 AC 123 ms
55,620 KB
testcase_21 AC 122 ms
56,204 KB
testcase_22 AC 127 ms
56,100 KB
testcase_23 AC 122 ms
56,188 KB
testcase_24 AC 121 ms
55,972 KB
testcase_25 AC 122 ms
56,116 KB
testcase_26 AC 121 ms
55,968 KB
testcase_27 AC 121 ms
56,096 KB
testcase_28 AC 120 ms
55,580 KB
testcase_29 AC 121 ms
55,820 KB
testcase_30 AC 121 ms
55,956 KB
testcase_31 AC 122 ms
55,772 KB
testcase_32 AC 121 ms
55,988 KB
testcase_33 AC 119 ms
55,988 KB
testcase_34 AC 120 ms
55,812 KB
testcase_35 AC 122 ms
56,300 KB
testcase_36 AC 121 ms
56,288 KB
testcase_37 AC 123 ms
56,012 KB
testcase_38 AC 125 ms
56,100 KB
testcase_39 AC 121 ms
55,760 KB
testcase_40 AC 120 ms
56,192 KB
testcase_41 AC 123 ms
55,964 KB
testcase_42 AC 120 ms
56,192 KB
testcase_43 AC 121 ms
56,088 KB
testcase_44 AC 120 ms
56,132 KB
testcase_45 AC 120 ms
56,004 KB
権限があれば一括ダウンロードができます

ソースコード

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