結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2015-07-24 16:37:29 |
言語 | C90 (gcc 12.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 519 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 22,528 KB |
実行使用メモリ | 14,912 KB |
最終ジャッジ日時 | 2024-07-08 12:58:01 |
合計ジャッジ時間 | 4,555 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | TLE * 1 -- * 25 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:20:34: warning: implicit declaration of function ‘abs’ [-Wimplicit-function-declaration] 20 | count += abs(c[i] - num); | ^~~ main.c:3:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘abs’ 2 | #include <math.h> +++ |+#include <stdlib.h> 3 | main.c:20:43: warning: ‘abs’ argument 1 type is ‘long long int’ where ‘int’ is expected in a call to built-in function declared without prototype [-Wbuiltin-declaration-mismatch] 20 | count += abs(c[i] - num); | ~~~~~^~~~~ <built-in>: note: built-in ‘abs’ declared here main.c:25:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=] 25 | printf("%d\n", min_count); | ~^ ~~~~~~~~~ | | | | int long long int | %lld main.c:8:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | scanf("%lld", &b); | ^~~~~~~~~~~~~~~~~ main.c:10:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%lld", &n); | ^~~~~~~~~~~~~~~~~ main.c:12:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%lld", &c[i]); | ^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <math.h> int main(void) { long long int i, j; long long int b, n, c[10]; long long int sum, num, count, min_count; scanf("%lld", &b); sum = 0; scanf("%lld", &n); for(i = 0;i < n;i++){ scanf("%lld", &c[i]); sum += c[i]; } min_count = -1; for(j = 0;j <= b;j++){ num = (sum + j) / n; count = 0; for(i = 0;i < n;i++){ count += abs(c[i] - num); } if(min_count == -1 || min_count >= count)min_count = count; else break; } printf("%d\n", min_count); return 0; }