結果

問題 No.1869 Doubling?
ユーザー tentententen
提出日時 2023-08-08 11:16:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,963 bytes
コンパイル時間 2,956 ms
コンパイル使用メモリ 88,672 KB
実行使用メモリ 37,428 KB
最終ジャッジ日時 2024-04-26 04:18:40
合計ジャッジ時間 6,378 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
37,152 KB
testcase_01 AC 51 ms
37,108 KB
testcase_02 AC 51 ms
37,188 KB
testcase_03 AC 50 ms
37,280 KB
testcase_04 AC 51 ms
37,028 KB
testcase_05 AC 50 ms
36,844 KB
testcase_06 AC 51 ms
36,948 KB
testcase_07 AC 50 ms
37,288 KB
testcase_08 AC 50 ms
37,016 KB
testcase_09 AC 51 ms
37,180 KB
testcase_10 AC 51 ms
36,924 KB
testcase_11 AC 52 ms
36,840 KB
testcase_12 AC 53 ms
37,092 KB
testcase_13 AC 52 ms
37,284 KB
testcase_14 AC 52 ms
37,428 KB
testcase_15 AC 53 ms
37,324 KB
testcase_16 AC 52 ms
37,240 KB
testcase_17 AC 52 ms
36,828 KB
testcase_18 AC 50 ms
36,780 KB
testcase_19 AC 51 ms
37,348 KB
testcase_20 AC 50 ms
37,272 KB
testcase_21 AC 51 ms
36,796 KB
testcase_22 AC 51 ms
37,336 KB
testcase_23 AC 51 ms
37,204 KB
testcase_24 AC 51 ms
37,328 KB
testcase_25 AC 52 ms
36,832 KB
testcase_26 AC 50 ms
37,136 KB
testcase_27 AC 50 ms
37,176 KB
testcase_28 AC 53 ms
37,280 KB
testcase_29 AC 51 ms
37,300 KB
testcase_30 AC 51 ms
37,308 KB
testcase_31 AC 51 ms
37,048 KB
testcase_32 AC 51 ms
36,684 KB
testcase_33 AC 50 ms
37,280 KB
testcase_34 AC 52 ms
37,132 KB
testcase_35 AC 51 ms
37,120 KB
testcase_36 AC 51 ms
37,228 KB
testcase_37 AC 50 ms
36,844 KB
testcase_38 AC 52 ms
37,332 KB
testcase_39 AC 52 ms
37,332 KB
testcase_40 AC 57 ms
37,316 KB
testcase_41 AC 51 ms
37,280 KB
testcase_42 AC 51 ms
37,080 KB
testcase_43 AC 51 ms
37,088 KB
testcase_44 AC 51 ms
37,096 KB
testcase_45 AC 51 ms
37,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        long ans = 0;
        if (n > 31 || (1 << (n - 1)) > m) {
            for (int i = n; i >= 1; i--) {
                if (m == 1) {
                    ans += i;
                    break;
                }
                ans += m;
                if (m % 2 == 0) {
                    m /= 2;
                } else {
                    m = (m + 1) / 2;
                }
            }
        } else {
            ans = (1 << n) - 1;
        }
        System.out.println(ans);
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0