algo

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub kuhaku-space/algo

:heavy_check_mark: ランレングス圧縮 (lib/algorithm/rle.hpp)

Verified with

Code

#pragma once
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector>

/// @brief ランレングス圧縮
template <class Container>
auto run_length_encoding(const Container &v) {
    std::vector<std::pair<std::decay_t<decltype(*std::begin(v))>, int>> res;
    for (auto &&e : v) {
        if (res.empty() || res.back().first != e) res.emplace_back(e, 1);
        else ++res.back().second;
    }
    return res;
}
#line 2 "lib/algorithm/rle.hpp"
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector>

/// @brief ランレングス圧縮
template <class Container>
auto run_length_encoding(const Container &v) {
    std::vector<std::pair<std::decay_t<decltype(*std::begin(v))>, int>> res;
    for (auto &&e : v) {
        if (res.empty() || res.back().first != e) res.emplace_back(e, 1);
        else ++res.back().second;
    }
    return res;
}
Back to top page