結果

問題 No.33 アメーバがたくさん
ユーザー 37zigen37zigen
提出日時 2020-03-30 04:44:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 1,016 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 79,968 KB
実行使用メモリ 56,572 KB
最終ジャッジ日時 2023-08-30 20:16:33
合計ジャッジ時間 4,918 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,784 KB
testcase_01 AC 120 ms
55,932 KB
testcase_02 AC 121 ms
55,812 KB
testcase_03 AC 120 ms
55,524 KB
testcase_04 AC 119 ms
55,844 KB
testcase_05 AC 120 ms
56,208 KB
testcase_06 AC 121 ms
55,588 KB
testcase_07 AC 120 ms
56,172 KB
testcase_08 AC 123 ms
55,844 KB
testcase_09 AC 130 ms
56,212 KB
testcase_10 AC 122 ms
56,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	long solve(long D,long T,long[] X) {
		int n=X.length;
		Arrays.sort(X);
		long ret=0;
		for(int i=0;i<n;++i){
			int j=i;
			while(j+1<n&&X[j+1]-X[j]<=2*D*T)++j;
			ret+=2*T+((X[j]-X[i])/D+1);
			i=j;
		}
		return ret;
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long D=sc.nextLong();
		long T=sc.nextLong();
		long[] X=new long[N];
		for(int i=0;i<N;++i) {
			X[i]=sc.nextLong()+(long)1e9;
		}
		for(int i=0;i<N;++i) {
			for(int j=i+1;j<N;++j) {
				if(X[i]%D<X[j]%D) {
					X[i]^=X[j];X[j]^=X[i];X[i]^=X[j];
				}
			}
		}
		long ans=0;
		for(int i=0;i<N;++i) {
			int j=i;
			while(j+1<N&&X[i]%D==X[j+1]%D) {
				++j;
			}
			ans+=solve(D,T,Arrays.copyOfRange(X, i, j+1));
			i=j;
		}
		System.out.println(ans);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

0