結果

問題 No.343 手抜き工事のプロ
ユーザー prime_mgm
提出日時 2016-02-14 19:38:11
言語 Java
(openjdk 23)
結果
AC  
実行時間 560 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 77,224 KB
実行使用メモリ 61,300 KB
最終ジャッジ日時 2024-09-22 06:36:48
合計ジャッジ時間 9,380 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int L = sc.nextInt();
		int[] minX = new int[N];// 上から順に0,1,2,...と振る
		int[] maxX = new int[N];
		double[] G = new double[N-1];
		int count_glue = 0;

		boolean flag = false;
		minX[N-1] = 0;
		maxX[N-1] = L;
		for(int i=N-2;i>=0;i--){
			minX[i] = sc.nextInt();
			maxX[i] = minX[i]+L;
			if(minX[i+1] >= maxX[i] || maxX[i+1] <= minX[i])flag = true;
		}
		sc.close();

		if(flag)System.out.println(-1);
		else{
			double sum = 0;
			for(int i=0;i<N-1;i++){
				sum += minX[i];
				G[i] = sum/(i+1) + L/2.0;

				boolean notfixed = G[i] <= minX[i+1] || G[i] >= maxX[i+1]
						|| G[i] <= minX[i] || G[i] >= maxX[i];
				if(notfixed){
					count_glue++;
				}
			}
			System.out.println(count_glue);
		}
	}

}
0