結果

問題 No.33 アメーバがたくさん
ユーザー tentententen
提出日時 2021-01-19 18:00:34
言語 Java19
(openjdk 21)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 1,050 bytes
コンパイル時間 3,016 ms
コンパイル使用メモリ 75,244 KB
実行使用メモリ 56,716 KB
最終ジャッジ日時 2023-08-22 15:05:39
合計ジャッジ時間 5,193 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,984 KB
testcase_01 AC 122 ms
55,644 KB
testcase_02 AC 120 ms
56,252 KB
testcase_03 AC 119 ms
55,792 KB
testcase_04 AC 120 ms
56,368 KB
testcase_05 AC 120 ms
56,008 KB
testcase_06 AC 119 ms
56,716 KB
testcase_07 AC 120 ms
56,232 KB
testcase_08 AC 121 ms
56,400 KB
testcase_09 AC 126 ms
56,356 KB
testcase_10 AC 118 ms
56,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int BASE = 1000000000;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		long t = sc.nextInt();
		HashMap<Integer, TreeSet<Integer>> ameba = new HashMap<>();
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt() + BASE;
		    int mod = x % d;
		    int div = x / d;
		    if (!ameba.containsKey(mod)) {
		        ameba.put(mod, new TreeSet<>());
		    }
		    ameba.get(mod).add(div);
		}
		long ans = 0;
		for (TreeSet<Integer> set : ameba.values()) {
		    int left = -1;
		    int right = -1;
		    for (int x : set) {
		        if (left == -1) {
		            left = x;
		            right = x;
		            continue;
		        }
		        if (x - right > 2 * t) {
		            ans += right - left + 1 + 2 * t;
		            left = x;
		            right = x;
		        } else {
		            right = x;
		        }
		    }
		    ans += right - left + 1 + 2 * t;
		}
		System.out.println(ans);
	}
}
0