#include #define PROBLEM "https://yukicoder.me/problems/no/1469" #include #include #include namespace mtd { template class RunLengthEncoding { using T = std::iter_value_t>; const std::vector> r; static constexpr auto construct_rle(const _R& r) { std::vector> rle; if (r.empty()) { return rle; } T now = *r.begin(); int cnt = 1; for (const auto& x : r | std::views::drop(1)) { if (x == now) { ++cnt; } else { rle.emplace_back(now, cnt); cnt = 1; now = x; } } rle.emplace_back(now, cnt); return rle; } public: constexpr RunLengthEncoding(const _R& r) : r(construct_rle(r)) {} constexpr auto begin() const { return r.begin(); } constexpr auto end() const { return r.end(); } };} #include #include #include #include namespace mtd { namespace io { namespace type { template struct vec { using value_type = T; static constexpr int pre = Pre; static constexpr int size = Size; }; template concept is_vec = requires { std::is_same_v>; }; } template auto _input(int n) { std::vector v(n); for (auto i : std::views::iota(0, n)) { std::cin >> v[i]; } return v; } template auto _input() { T x; std::cin >> x; return x; } template auto _tuple_input(Tuple& t) { if constexpr (type::is_vec) { if constexpr (T::size == 0) { std::get(t) = _input(std::get(t)); } else { std::get(t) = _input(T::size); } } else { std::get(t) = _input(); } if constexpr (sizeof...(Args) > 0) { _tuple_input(t); } } template struct _Converter { using type = T; }; template struct _Converter> { using type = std::vector; }; template auto in() { auto base = std::tuple::type...>(); _tuple_input<0, decltype(base), Args...>(base); return base; } } } #include namespace mtd { namespace ranges { constexpr int _inf = 1e9; template struct istream_view : public std::ranges::view_interface> { class iterator { int count; std::tuple::type...> val; public: using difference_type = int; using value_type = decltype(val); using iterator_concept = std::input_iterator_tag; constexpr iterator() = default; constexpr explicit iterator(int count) : count(count) { operator++(); } constexpr auto operator*() const { return val; } constexpr auto& operator++() { --count; if (count >= 0) { val = io::in(); } return *this; } constexpr auto operator++(int) { return ++*this; } constexpr auto operator==(const iterator& s) const { return count == s.count; } constexpr auto operator==(std::default_sentinel_t s) const { return count < 0 || std::cin.eof() || std::cin.fail() || std::cin.bad(); } constexpr friend auto operator==(std::default_sentinel_t s, const iterator& li) { return li == s; } }; int count; public: constexpr explicit istream_view(int count) : count(count) {} constexpr explicit istream_view() : istream_view(_inf) {} constexpr auto begin() const { return iterator(count); } constexpr auto end() const { return std::default_sentinel; } }; } namespace views { namespace __detail { template concept __can_istream_view = requires { ranges::istream_view(std::declval<_Args>()...); }; } template struct _Istream { template requires __detail::__can_istream_view<_Tp...> constexpr auto operator() [[nodiscard]] (_Tp&&... __e) const { return ranges::istream_view(std::forward<_Tp>(__e)...); } }; template inline constexpr _Istream istream{}; } } int main() { std::cin.tie(0); std::ios::sync_with_stdio(0); auto [s] = mtd::io::in(); auto rle = mtd::RunLengthEncoding(s); for (auto [c, _] : rle) { std::cout << c; } std::cout << std::endl; }