結果

問題 No.3260 岩井スターグラフ
ユーザー elphe
提出日時 2025-08-07 11:30:28
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 2,941 ms
コンパイル使用メモリ 278,416 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2025-08-07 11:30:39
合計ジャッジ時間 10,142 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

static inline constexpr std::vector<uint_fast32_t> solve(const uint_fast32_t X, const uint_fast32_t Y, const uint_fast32_t N, const std::vector<uint_fast64_t>& U, const std::vector<uint_fast64_t>& V) noexcept
{
	std::vector<uint_fast32_t> ans(N);
	for (uint_fast32_t i = 0; i != N; ++i)
	{
		if (U[i] == 0)
			ans[i] = (V[i] - 1) % Y + 1;
		else if ((U[i] - 1) / Y == (V[i] - 1) / Y)
			ans[i] = V[i] - U[i];
		else
			ans[i] = ((U[i] - 1) % Y + 1) + ((V[i] - 1) % Y + 1);
	}

	return ans;
}

static inline void output(const uint_fast32_t N, const std::vector<uint_fast32_t>& ans) noexcept
{
	for (uint_fast32_t i = 0; i != N; ++i)
		std::cout << ans[i] << '\n';
}

int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	
	uint_fast32_t X, Y, N, i;
	std::cin >> X >> Y >> N;

	std::vector<uint_fast64_t> U(N), V(N);
	for (i = 0; i != N; ++i)
		std::cin >> U[i] >> V[i];

	output(N, solve(X, Y, N, U, V));
	return 0;
}
0