結果

問題 No.3241 Make Multiplication of 8
ユーザー elphe
提出日時 2025-08-22 22:20:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 3,101 ms
コンパイル使用メモリ 277,936 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-22 22:20:49
合計ジャッジ時間 4,547 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

[[nodiscard]] static inline constexpr std::array<uint_fast64_t, 4> prepare([[maybe_unused]] const uint_fast32_t N, const std::vector<std::pair<uint_least32_t, uint_least32_t>>& cards) noexcept
{
	std::array<uint_fast64_t, 4> count_of = { 0, 0, 0, 0 };
	for (const auto& [a, b] : cards)
	{
		if ((a & 7) == 0) count_of[3] += b;
		else if ((a & 3) == 0) count_of[2] += b;
		else if ((a & 1) == 0) count_of[1] += b;
		else count_of[0] += b;
	}

	return count_of;
}

[[nodiscard]] static inline constexpr uint_fast64_t solve(const std::array<uint_fast64_t, 4>& count_of) noexcept
{
	if (count_of[1] <= count_of[2])
		return count_of[1] + count_of[3] + (count_of[2] - count_of[1]) / 2;
	else
		return count_of[2] + count_of[3] + (count_of[1] - count_of[2]) / 3;
}

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

	uint_fast32_t N;
	std::cin >> N;
	std::vector<std::pair<uint_least32_t, uint_least32_t>> cards(N);
	for (auto& [a, b] : cards)
		std::cin >> a >> b;

	std::cout << solve(prepare(N, cards)) << '\n';
	return 0;
}
0