結果

問題 No.3288 Sloppy Land Grading
コンテスト
ユーザー pengin_2000
提出日時 2025-10-03 21:57:52
言語 C
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 619 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 175 ms
コンパイル使用メモリ 38,848 KB
最終ジャッジ日時 2026-02-22 13:48:46
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:15: warning: conflicting types for built-in function 'abs'; expected 'int(int)' [-Wbuiltin-declaration-mismatch]
    2 | long long int abs(long long int n)
      |               ^~~
main.c:2:1: note: 'abs' is declared in header '<stdlib.h>'
    1 | #include<stdio.h>
  +++ |+#include <stdlib.h>
    2 | long long int abs(long long int n)

ソースコード

diff #
raw source code

#include<stdio.h>
long long int abs(long long int n)
{
	if (n < 0)
		return -n;
	else
		return n;
}
long long int num[3], cost[3];
long long int cal(long long int x)
{
	long long int res = 0, i;
	for (i = 0; i < 3; i++)
		res += cost[i] * abs(x - num[i]);
	return res;
}
void solve()
{
	long long int i;
	for (i = 0; i < 3; i++)
		scanf("%d", &num[i]);
	for (i = 0; i < 3; i++)
		scanf("%d", &cost[i]);
	long long int ans = 1e18;
	for (i = 0; i < 3; i++)
		if (ans > cal(num[i]))
			ans = cal(num[i]);
	printf("%lld\n", ans);
	return;
}
int main()
{
	int t;
	scanf("%d", &t);
	for (; t > 0; t--)
		solve();
	return 0;
}
0