結果
問題 |
No.33 アメーバがたくさん
|
ユーザー |
![]() |
提出日時 | 2021-01-19 18:00:34 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 135 ms / 5,000 ms |
コード長 | 1,050 bytes |
コンパイル時間 | 2,579 ms |
コンパイル使用メモリ | 79,456 KB |
実行使用メモリ | 54,380 KB |
最終ジャッジ日時 | 2024-12-17 14:17:42 |
合計ジャッジ時間 | 4,487 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 |
ソースコード
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); } }