結果

問題 No.1869 Doubling?
ユーザー shojin_proshojin_pro
提出日時 2022-03-11 21:27:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 10,133 bytes
コンパイル時間 6,571 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 51,688 KB
最終ジャッジ日時 2023-10-14 06:14:18
合計ジャッジ時間 6,540 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,300 KB
testcase_01 AC 44 ms
49,532 KB
testcase_02 AC 43 ms
49,408 KB
testcase_03 AC 43 ms
49,628 KB
testcase_04 AC 44 ms
49,612 KB
testcase_05 AC 44 ms
49,512 KB
testcase_06 AC 43 ms
49,428 KB
testcase_07 AC 44 ms
49,512 KB
testcase_08 AC 43 ms
49,204 KB
testcase_09 WA -
testcase_10 AC 44 ms
49,388 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 43 ms
49,628 KB
testcase_16 AC 44 ms
49,300 KB
testcase_17 AC 43 ms
49,240 KB
testcase_18 AC 45 ms
49,340 KB
testcase_19 AC 44 ms
49,148 KB
testcase_20 AC 44 ms
49,296 KB
testcase_21 AC 43 ms
49,236 KB
testcase_22 AC 44 ms
49,432 KB
testcase_23 AC 43 ms
49,312 KB
testcase_24 AC 43 ms
49,796 KB
testcase_25 AC 45 ms
49,236 KB
testcase_26 AC 44 ms
49,416 KB
testcase_27 AC 43 ms
49,292 KB
testcase_28 AC 43 ms
49,520 KB
testcase_29 AC 44 ms
49,404 KB
testcase_30 AC 43 ms
49,344 KB
testcase_31 AC 43 ms
49,368 KB
testcase_32 AC 44 ms
49,988 KB
testcase_33 AC 44 ms
51,416 KB
testcase_34 AC 43 ms
49,144 KB
testcase_35 AC 43 ms
49,292 KB
testcase_36 AC 44 ms
49,604 KB
testcase_37 AC 43 ms
49,236 KB
testcase_38 AC 44 ms
49,388 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 42 ms
49,424 KB
testcase_43 AC 44 ms
49,136 KB
testcase_44 WA -
testcase_45 AC 43 ms
49,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static ContestScanner sc = new ContestScanner(System.in);
    static PrintWriter pw = new PrintWriter(System.out);
    static StringBuilder sb = new StringBuilder();
    static long mod = (long) 1e9 + 7;

    public static void main(String[] args) throws Exception {
        solve();
        pw.flush();
    }

    public static void solve() {
        long N = sc.nextLong();
        long M = sc.nextLong();
        long ans = 0;
        while(N > 0 && M > 1){
            ans += M;
            M = (M+1)/2;
            N--;
        }
        pw.println(ans + N);
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

        public static void save_sort(long[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static long[] shuffle(long[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                long randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

    }
}

/**
 * 単一始点最短経路問題と呼ぶらしい
 * verified - https://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=6293383#1
 */

class Dijkstra {
    static ArrayList<ArrayList<Edge>> graph = new ArrayList<>();
    static long MAX = (long) 1e14;

    public Dijkstra(int N) {
        for (int i = 0; i < N; i++)
            graph.add(new ArrayList<>());
    }

    public void addEdge(int a, int b, long c) {
        graph.get(a).add(new Edge(b, c));
    }

    static long[] dijkstra(int v, int N) {
        long[] dist = new long[N];
        Arrays.fill(dist, MAX);
        dist[v] = 0;
        PriorityQueue<Vertex> pq = new PriorityQueue<Vertex>((p1, p2) -> {
            if (p1.dist == p2.dist)
                return 0;
            return p1.dist - p2.dist < 0 ? -1 : 1;
        });

        pq.add(new Vertex(v, 0));
        while (!pq.isEmpty()) {
            Vertex now = pq.poll();
            int id = now.id;
            long d = now.dist;
            if (dist[id] < d)
                continue;
            for (Edge e : graph.get(id)) {
                int to = e.to;
                if (dist[to] > dist[id] + e.cost) {
                    dist[to] = dist[id] + e.cost;
                    pq.add(new Vertex(to, dist[to]));
                }
            }
        }
        return dist;
    }

    static class Edge {
        int to;
        long cost;

        public Edge(int to, long cost) {
            this.to = to;
            this.cost = cost;
        }

    }

    static class Vertex {
        int id;
        long dist;

        public Vertex(int id, long dist) {
            this.id = id;
            this.dist = dist;
        }
    }
}


/**
 * refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java
 */
class ContestScanner {
    private final java.io.InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private static final long LONG_MAX_TENTHS = 922337203685477580L;
    private static final int LONG_MAX_LAST_DIGIT = 7;
    private static final int LONG_MIN_LAST_DIGIT = 8;

    public ContestScanner(java.io.InputStream in){
        this.in = in;
    }
    public ContestScanner(java.io.File file) throws java.io.FileNotFoundException {
        this(new java.io.BufferedInputStream(new java.io.FileInputStream(file)));
    }
    public ContestScanner(){
        this(System.in);
    }
 
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { 
        if (hasNextByte()) return buffer[ptr++]; else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new java.util.NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext()) throw new java.util.NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                int digit = b - '0';
                if (n >= LONG_MAX_TENTHS) {
                    if (n == LONG_MAX_TENTHS) {
                        if (minus) {
                            if (digit <= LONG_MIN_LAST_DIGIT) {
                                n = -n * 10 - digit;
                                b = readByte();
                                if (!isPrintableChar(b)) {
                                    return n;
                                } else if (b < '0' || '9' < b) {
                                    throw new NumberFormatException(
                                        String.format("%d%s... is not number", n, Character.toString(b))
                                    );
                                }
                            }
                        } else {
                            if (digit <= LONG_MAX_LAST_DIGIT) {
                                n = n * 10 + digit;
                                b = readByte();
                                if (!isPrintableChar(b)) {
                                    return n;
                                } else if (b < '0' || '9' < b) {
                                    throw new NumberFormatException(
                                        String.format("%d%s... is not number", n, Character.toString(b))
                                    );
                                }
                            }
                        }
                    }
                    throw new ArithmeticException(
                        String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit)
                    );
                }
                n = n * 10 + digit;
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
 
    public long[] nextLongArray(int length){
        long[] array = new long[length];
        for(int i=0; i<length; i++) array[i] = this.nextLong();
        return array;
    }
    public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map){
        long[] array = new long[length];
        for(int i=0; i<length; i++) array[i] = map.applyAsLong(this.nextLong());
        return array;
    }
    public int[] nextIntArray(int length){
        int[] array = new int[length];
        for(int i=0; i<length; i++) array[i] = this.nextInt();
        return array;
    }
    public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map){
        int[] array = new int[length];
        for(int i=0; i<length; i++) array[i] = map.applyAsInt(this.nextInt());
        return array;
    }
    public double[] nextDoubleArray(int length){
        double[] array = new double[length];
        for(int i=0; i<length; i++) array[i] = this.nextDouble();
        return array;
    }
    public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map){
        double[] array = new double[length];
        for(int i=0; i<length; i++) array[i] = map.applyAsDouble(this.nextDouble());
        return array;
    }
 
    public long[][] nextLongMatrix(int height, int width){
        long[][] mat = new long[height][width];
        for(int h=0; h<height; h++) for(int w=0; w<width; w++){
            mat[h][w] = this.nextLong();
        }
        return mat;
    }
    public int[][] nextIntMatrix(int height, int width){
        int[][] mat = new int[height][width];
        for(int h=0; h<height; h++) for(int w=0; w<width; w++){
            mat[h][w] = this.nextInt();
        }
        return mat;
    }
    public double[][] nextDoubleMatrix(int height, int width){
        double[][] mat = new double[height][width];
        for(int h=0; h<height; h++) for(int w=0; w<width; w++){
            mat[h][w] = this.nextDouble();
        }
        return mat;
    }
 
    public char[][] nextCharMatrix(int height, int width){
        char[][] mat = new char[height][width];
        for(int h=0; h<height; h++){
            String s = this.next();
            for(int w=0; w<width; w++){
                mat[h][w] = s.charAt(w);
            }
        }
        return mat;
    }
}
0