結果

問題 No.3324 ハイライト動画
コンテスト
ユーザー elphe
提出日時 2025-08-22 11:37:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,495 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 3,409 ms
コンパイル使用メモリ 281,224 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-01 14:30:58
合計ジャッジ時間 20,380 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

// O(N + M) 解法
[[nodiscard]] static inline constexpr std::vector<std::pair<uint_least32_t, uint_least32_t>> solve(const uint_fast32_t N, const uint_fast32_t M, const std::vector<uint_least32_t>& A) noexcept
{
	std::vector<std::pair<uint_least32_t, uint_least32_t>> ans;
	ans.reserve(M);
	uint_fast32_t i, j, length;
	for (i = 1, j = 0, length = 0; i <= N && j != M; ++i)
	{
		if (i == A[j]) ++length, ++j;
		else if (length != 0) ans.emplace_back(i - length, length), length = 0;
	}
	ans.emplace_back(i - length, length);

	return ans;
}

static inline void output(const std::vector<std::pair<uint_least32_t, uint_least32_t>>& ans) noexcept
{
	std::cout << ans.size() << '\n';
	for (const auto& [S, L] : ans)
		std::cout << S << ' ' << L << '\n';
}

int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	
	uint_fast32_t N, M;
	std::cin >> N >> M;
	std::vector<uint_least32_t> A(M);
	for (auto& a : A) std::cin >> a;

	output(solve(N, M, A));
	return 0;
}
0