結果

問題 No.1869 Doubling?
ユーザー tentententen
提出日時 2022-09-28 09:18:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,480 bytes
コンパイル時間 5,030 ms
コンパイル使用メモリ 73,756 KB
実行使用メモリ 49,824 KB
最終ジャッジ日時 2023-08-24 04:16:46
合計ジャッジ時間 6,023 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,488 KB
testcase_01 AC 42 ms
49,320 KB
testcase_02 AC 41 ms
49,608 KB
testcase_03 AC 41 ms
49,368 KB
testcase_04 AC 41 ms
49,364 KB
testcase_05 AC 42 ms
49,284 KB
testcase_06 AC 41 ms
49,524 KB
testcase_07 AC 41 ms
49,276 KB
testcase_08 AC 41 ms
49,688 KB
testcase_09 AC 40 ms
49,708 KB
testcase_10 AC 41 ms
49,360 KB
testcase_11 AC 42 ms
49,824 KB
testcase_12 AC 42 ms
49,244 KB
testcase_13 AC 41 ms
47,224 KB
testcase_14 AC 42 ms
49,352 KB
testcase_15 AC 41 ms
49,444 KB
testcase_16 AC 41 ms
49,680 KB
testcase_17 AC 41 ms
49,604 KB
testcase_18 AC 40 ms
49,300 KB
testcase_19 AC 42 ms
49,292 KB
testcase_20 AC 41 ms
49,356 KB
testcase_21 AC 45 ms
49,308 KB
testcase_22 AC 41 ms
49,480 KB
testcase_23 AC 42 ms
49,428 KB
testcase_24 AC 41 ms
49,156 KB
testcase_25 AC 41 ms
49,624 KB
testcase_26 AC 41 ms
49,252 KB
testcase_27 AC 41 ms
49,272 KB
testcase_28 AC 41 ms
49,352 KB
testcase_29 AC 41 ms
47,672 KB
testcase_30 AC 45 ms
49,248 KB
testcase_31 AC 45 ms
49,296 KB
testcase_32 AC 42 ms
49,324 KB
testcase_33 AC 42 ms
49,500 KB
testcase_34 AC 42 ms
49,364 KB
testcase_35 AC 40 ms
49,356 KB
testcase_36 AC 41 ms
49,520 KB
testcase_37 AC 41 ms
49,468 KB
testcase_38 AC 41 ms
49,420 KB
testcase_39 AC 40 ms
49,360 KB
testcase_40 AC 42 ms
49,676 KB
testcase_41 AC 44 ms
49,468 KB
testcase_42 AC 42 ms
49,168 KB
testcase_43 AC 41 ms
49,312 KB
testcase_44 AC 40 ms
49,112 KB
testcase_45 AC 43 ms
49,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int start;
        if (n < 31 && m > (1 << (n - 1))) {
            start = (1 << (n - 1));
        } else {
            start = m;
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (start == 1) {
                ans += n - i;
                break;
            }
            ans += start;
            if (start % 2 == 0) {
                start /= 2;
            } else {
                start = (start + 1) / 2;
            }
        }
        System.out.println(ans);
    }
}
    
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0