結果

問題 No.343 手抜き工事のプロ
ユーザー bal4ubal4u
提出日時 2019-08-23 06:00:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 15:28:22
合計ジャッジ時間 2,710 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:13:24: note: in expansion of macro 'gc'
   13 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.343 手抜き工事のプロ
// 2019.8.23 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {  // 整数の入力(負数対応)
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

// 重心の座標を整数にしたいので、以下では長さの単位を倍にした
int N, L;
int X[100005]; // 各鋼材の重心座標

inline static int ABS(int a) { return a >= 0? a: -a; }

int main()
{
	int i, j, wj, w, s, ans;
	
	N = in(), w = in(), L = w << 1;  // w は L の半分
	X[1] = w; for (i = 2; i <= N; i++) {
		X[i] = (in()<<1) + w; // 重心座標 (x_i + L/2)の2倍
		if (ABS(X[i]-X[i-1]) >= L) { puts("-1"); return 0; } // 上下の鋼材は重ねていない
	}
	
	// 溶接箇所のカウント
	ans = 0;
	j = 1, wj = w, s = 0; for (i = N-1; i; i--) {
		s += X[i+1];
		if (ABS(s - X[i]*j) >= wj || ABS(s - X[i+1]*j) >= wj) ans++;
		j++, wj += w;
	}
	printf("%d\n", ans);
	return 0;
}
0