結果

問題 No.343 手抜き工事のプロ
ユーザー FF256grhyFF256grhy
提出日時 2015-08-04 17:50:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 26,196 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 01:05:15
合計ジャッジ時間 2,305 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 12 ms
4,380 KB
testcase_26 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 想定解法

#include <stdio.h>

#define MAX_N 100000
#define MAX_L  10000
#define MAX_X   5000

int n, l, x[MAX_N], sum[MAX_N];

int abs(int a) { return 0 < a ? a : -a; }

int main(void) {
	int i;
	scanf("%d%d", &n, &l);
	
	// assert
	if( ! ( 1 <= n && n <= MAX_N ) ) { return 0; }
	if( ! ( 1 <= l && l <= MAX_L ) ) { return 0; }
	
	// 色々と面倒なので, x[i] には上から i 番目を入れる
	x[n - 1] = 0;
	for(i = n - 2; 0 <= i; i--) {
		scanf("%d", &x[i]);
		
		// assert
		if( ! ( abs( x[i] ) <= MAX_X ) ) { return 0; }
	}
	
	// sum[i] は i より上の座標の和, i より上の重心座標は sum[i]/i
	sum[0] = 0;
	for(i = 1; i < n; i++) {
		sum[i] = sum[i - 1] + x[i - 1];
	}
	
	int counter = 0;
	for(i = 1; i < n; i++) {
		if( l <= abs(x[i - 1] - x[i]) ) { counter = -1; break; }
		if(
			// l/2 <= abs( sum[i]/i - x[i] ) の両辺に 2i を掛けた
			i * l <= abs( 2 * sum[i] - 2 * i * x[i] ) ||
			i * l <= abs( 2 * sum[i] - 2 * i * x[i - 1] )
		) { counter++; }
	}
	printf("%d\n", counter);
	return 0;
}
0