結果

問題 No.33 アメーバがたくさん
ユーザー uafr_csuafr_cs
提出日時 2017-11-09 19:02:44
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,844 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 81,204 KB
実行使用メモリ 54,512 KB
最終ジャッジ日時 2024-05-03 08:50:21
合計ジャッジ時間 4,151 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
54,300 KB
testcase_01 AC 122 ms
53,828 KB
testcase_02 AC 123 ms
54,080 KB
testcase_03 AC 111 ms
52,788 KB
testcase_04 WA -
testcase_05 AC 114 ms
52,928 KB
testcase_06 AC 121 ms
54,312 KB
testcase_07 AC 111 ms
52,804 KB
testcase_08 WA -
testcase_09 AC 131 ms
54,052 KB
testcase_10 AC 114 ms
53,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
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>>();
		for(int i = 0; i < N; i++){
			final long X = sc.nextLong();
			final long mod = X % D;
			
			if(!mods.containsKey(mod)){
				mods.put(mod, new TreeSet<Long>());
			}
			mods.get(mod).add(X);
		}
		
		//long answer = 0;
		BigInteger answer = BigInteger.valueOf(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; }
			if(list.size() == 1){
				answer = answer.add(BigInteger.valueOf(2 * T + 1));
				continue;
			}
			
			
			/*
			answer += T;
			//System.out.println(answer);
			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;
			*/
			
			answer = answer.add(BigInteger.valueOf(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 = answer.add(BigInteger.valueOf(min + 1));
			}
			answer = answer.add(BigInteger.valueOf(T + 1));
		}
		
		System.out.println(answer);
	}
}
0