結果

問題 No.2486 Don't come next to me
ユーザー tentententen
提出日時 2024-04-03 14:46:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 1,645 bytes
コンパイル時間 2,394 ms
コンパイル使用メモリ 79,248 KB
実行使用メモリ 68,484 KB
最終ジャッジ日時 2024-04-03 14:46:46
合計ジャッジ時間 9,232 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 308 ms
66,880 KB
testcase_01 AC 306 ms
66,344 KB
testcase_02 AC 195 ms
58,928 KB
testcase_03 AC 262 ms
63,812 KB
testcase_04 AC 290 ms
66,364 KB
testcase_05 AC 269 ms
63,804 KB
testcase_06 AC 299 ms
66,860 KB
testcase_07 AC 162 ms
57,808 KB
testcase_08 AC 226 ms
59,448 KB
testcase_09 AC 291 ms
65,900 KB
testcase_10 AC 291 ms
66,128 KB
testcase_11 AC 236 ms
61,148 KB
testcase_12 AC 190 ms
58,512 KB
testcase_13 AC 305 ms
68,484 KB
testcase_14 AC 227 ms
59,040 KB
testcase_15 AC 279 ms
64,316 KB
testcase_16 AC 171 ms
58,044 KB
testcase_17 AC 201 ms
59,408 KB
testcase_18 AC 197 ms
59,284 KB
testcase_19 AC 231 ms
59,468 KB
testcase_20 AC 55 ms
53,956 KB
testcase_21 AC 55 ms
53,988 KB
testcase_22 AC 55 ms
53,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static Map<Long, Long> dp = new HashMap<>();
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        int m = sc.nextInt();
        dp.put(1L, 1L);
        long prev = sc.nextLong();
        long ans = 0;
        for (int i = 1; i < m; i++) {
            long x = sc.nextLong();
            ans += dfw(x - prev - 1);
            prev = x;
        }
        System.out.println(ans);
    }
    
    static long dfw(long x) {
        if (x == 1) {
            return 1;
        } else if (x % 2 == 0) {
            return x;
        } else {
            return dfw(x / 2) * 2;
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0