結果

問題 No.33 アメーバがたくさん
ユーザー uafr_csuafr_cs
提出日時 2017-11-09 19:36:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 1,417 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 81,448 KB
実行使用メモリ 41,840 KB
最終ジャッジ日時 2024-05-03 08:50:26
合計ジャッジ時間 4,094 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
41,480 KB
testcase_01 AC 114 ms
41,384 KB
testcase_02 AC 115 ms
41,308 KB
testcase_03 AC 125 ms
41,344 KB
testcase_04 AC 111 ms
41,376 KB
testcase_05 AC 126 ms
41,628 KB
testcase_06 AC 126 ms
41,376 KB
testcase_07 AC 123 ms
41,456 KB
testcase_08 AC 115 ms
41,576 KB
testcase_09 AC 129 ms
41,840 KB
testcase_10 AC 122 ms
41,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static long MOD = 1000000007;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final long D = sc.nextLong();
		final long T = sc.nextLong();
		
		HashMap<Long, TreeSet<Long>> mods = new HashMap<Long, TreeSet<Long>>();
		
		long[] xs = new long[N];
		for(int i = 0; i < N; i++){
			xs[i] = sc.nextLong();
		}
		final long min_xs = Arrays.stream(xs).min().getAsLong();
		
		for(int i = 0; i < N; i++){
			final long X = xs[i] - min_xs;
			final long mod = X % D;
			
			if(!mods.containsKey(mod)){
				mods.put(mod, new TreeSet<Long>());
			}
			mods.get(mod).add(X);
		}
		
		long answer = 0;
		for(final Entry<Long, TreeSet<Long>> entry : mods.entrySet()){
			final long mod = entry.getKey();
			final ArrayList<Long> list = new ArrayList<Long>(entry.getValue());
			
			if(list.size() == 1){ answer += (2 * T + 1); continue; }
			
			answer += T;
			for(int fst = 0; fst < list.size() - 1; fst++){
				final int snd = fst + 1;
				final long diff = (list.get(snd) - list.get(fst)) / D - 1;
				final long min = Math.min(diff, 2 * T);
				
				answer += min + 1;
			}
			answer += T + 1;
		}
		
		System.out.println(answer);
	}
}
0