結果

問題 No.3288 Sloppy Land Grading
ユーザー elphe
提出日時 2025-10-03 23:13:22
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,270 bytes
コンパイル時間 2,793 ms
コンパイル使用メモリ 279,368 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-03 23:13:28
合計ジャッジ時間 5,107 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

[[nodiscard]] static inline constexpr int_fast64_t check(const int_fast32_t A, const int_fast32_t B, const int_fast32_t C, const int_fast32_t x, const int_fast32_t y, const int_fast32_t z, const int_fast32_t c) noexcept
{
	return std::abs<int_fast64_t>(A - c) * x + std::abs<int_fast64_t>(B - c) * y + std::abs<int_fast64_t>(C - c) * z;
}

[[nodiscard]] static inline constexpr int_fast64_t solve(const int_fast32_t A, const int_fast32_t B, const int_fast32_t C, const int_fast32_t x, const int_fast32_t y, const int_fast32_t z) noexcept
{
	int_fast32_t l = std::min<int_fast32_t>({ A, B, C }), r = std::max<int_fast32_t>({ A, B, C }) + 1;
	while (l + 2 < r)
	{
		const int_fast32_t c1 = (l * 2 + r) / 3, c2 = (l + r * 2) / 3;
		if (check(A, B, C, x, y, z, c1) < check(A, B, C, x, y, z, c2))
			r = c2;
		else
			l = c1;
	}

	return std::min<int_fast64_t>({ check(A, B, C, x, y, z, l), check(A, B, C, x, y, z, l + 1), check(A, B, C, x, y, z, r - 1) });
}

int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	uint_fast32_t T;
	std::cin >> T;
	for (uint_fast32_t i = 0; i < T; ++i)
	{
		int_fast32_t A, B, C, x, y, z;
		std::cin >> A >> B >> C >> x >> y >> z;
		std::cout << solve(A, B, C, x, y, z) << '\n';
	}

	return 0;
}
0