結果
| 問題 |
No.343 手抜き工事のプロ
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-08-06 01:23:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 978 bytes |
| コンパイル時間 | 114 ms |
| コンパイル使用メモリ | 23,040 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-18 03:36:15 |
| 合計ジャッジ時間 | 1,211 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d%d", &n, &l);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:22:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | scanf("%d", &x[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
// 想定解法(改良版)
#include <stdio.h>
#define MAX_N 100000
#define MAX_L 10000
#define MAX_X 5000
int n, l, x[MAX_N];
int abs(int a) { return 0 < a ? a : -a; }
int main(void) {
int i;
scanf("%d%d", &n, &l);
if( ! ( 1 <= n && n <= MAX_N ) ) { return 0; } // assert
if( ! ( 1 <= l && l <= MAX_L ) ) { return 0; } // assert
// 色々と面倒なので, x[i] には上から i 番目を入れる
x[n - 1] = 0;
for(i = n - 2; 0 <= i; i--) {
scanf("%d", &x[i]);
if( ! ( abs( x[i] ) <= MAX_X ) ) { return 0; } // assert
}
// sum は i より上の座標の和, i より上の重心座標は sum/i
int counter = 0, sum = 0;
for(i = 1; i < n; i++) {
sum += x[i - 1];
if( l <= abs(x[i - 1] - x[i]) ) { counter = -1; break; }
if(
// l/2 <= abs( sum/i - x[i] ) の両辺に 2i を掛けた
i * l <= abs( 2 * sum - 2 * i * x[i] ) ||
i * l <= abs( 2 * sum - 2 * i * x[i - 1] )
) { counter++; }
}
printf("%d\n", counter);
return 0;
}
FF256grhy