結果

問題 No.343 手抜き工事のプロ
ユーザー prime_mgmprime_mgm
提出日時 2016-02-14 19:38:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 532 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 76,980 KB
実行使用メモリ 64,064 KB
最終ジャッジ日時 2023-10-22 05:18:25
合計ジャッジ時間 9,211 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
57,380 KB
testcase_01 AC 133 ms
57,636 KB
testcase_02 AC 131 ms
55,560 KB
testcase_03 AC 131 ms
57,412 KB
testcase_04 AC 129 ms
57,488 KB
testcase_05 AC 132 ms
57,552 KB
testcase_06 AC 132 ms
57,652 KB
testcase_07 AC 130 ms
57,456 KB
testcase_08 AC 131 ms
57,432 KB
testcase_09 AC 134 ms
57,416 KB
testcase_10 AC 130 ms
57,500 KB
testcase_11 AC 133 ms
57,672 KB
testcase_12 AC 149 ms
57,452 KB
testcase_13 AC 253 ms
60,852 KB
testcase_14 AC 187 ms
57,788 KB
testcase_15 AC 188 ms
57,680 KB
testcase_16 AC 135 ms
57,424 KB
testcase_17 AC 133 ms
57,456 KB
testcase_18 AC 131 ms
57,448 KB
testcase_19 AC 134 ms
57,412 KB
testcase_20 AC 257 ms
61,136 KB
testcase_21 AC 381 ms
59,956 KB
testcase_22 AC 357 ms
61,884 KB
testcase_23 AC 473 ms
62,024 KB
testcase_24 AC 490 ms
61,956 KB
testcase_25 AC 521 ms
63,900 KB
testcase_26 AC 532 ms
64,064 KB
権限があれば一括ダウンロードができます

ソースコード

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