結果

問題 No.2486 Don't come next to me
ユーザー tentententen
提出日時 2024-04-03 14:44:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 641 ms / 2,000 ms
コード長 1,651 bytes
コンパイル時間 2,409 ms
コンパイル使用メモリ 79,448 KB
実行使用メモリ 83,928 KB
最終ジャッジ日時 2024-04-03 14:44:57
合計ジャッジ時間 12,086 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 525 ms
83,928 KB
testcase_01 AC 485 ms
81,172 KB
testcase_02 AC 263 ms
64,080 KB
testcase_03 AC 456 ms
73,152 KB
testcase_04 AC 492 ms
78,760 KB
testcase_05 AC 435 ms
71,688 KB
testcase_06 AC 472 ms
79,044 KB
testcase_07 AC 183 ms
58,680 KB
testcase_08 AC 282 ms
63,796 KB
testcase_09 AC 487 ms
81,184 KB
testcase_10 AC 431 ms
70,844 KB
testcase_11 AC 307 ms
66,408 KB
testcase_12 AC 250 ms
61,988 KB
testcase_13 AC 641 ms
82,672 KB
testcase_14 AC 285 ms
63,888 KB
testcase_15 AC 423 ms
72,032 KB
testcase_16 AC 195 ms
58,564 KB
testcase_17 AC 270 ms
64,204 KB
testcase_18 AC 256 ms
61,924 KB
testcase_19 AC 285 ms
64,176 KB
testcase_20 AC 55 ms
53,980 KB
testcase_21 AC 55 ms
53,976 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 % 2 == 0) {
            return x;
        }
        if (!dp.containsKey(x)) {
            dp.put(x, dfw(x / 2) * 2);
        }
        return dp.get(x);
    }
}
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