Language: C++

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int inf = 1e18;
int main(){
    int N,M; cin >> N >> M;
    string s; cin >> s;
    vector<vector<int>>edge(N + 1);
    for(int i = 0; i + 1 < edge.size(); ++i)
        edge[i + 1].emplace_back(i);
    for(int i = 0; i + 1 < edge.size(); ++i){
        int nxt = min(N,i + M);
        edge[i].emplace_back(nxt);
    }
    vector<Int>d(N + 1,inf);
    vector<Int>memo(N + 1,inf);
    priority_queue<tuple<Int, Int,Int>,vector<tuple<Int,Int,Int>>,greater<>>que;
    que.emplace(0,0);
    d[0] = 0;
    memo[0] = 0;
    while(not que.empty()){
        Int k,cv,org;
        tie(k,cv,org) = que.top(); que.pop();
        if(d[cv] < k ) continue;
        for(auto nxt : edge[cv]){
            bool is_virtual = nxt < cv;
            if(is_virtual){
                if(d[nxt] > d[cv] + 1){
                    d[nxt] = d[cv];
                    memo[nxt] =  org;
                    que.emplace(d[nxt],nxt,org);
                } else if(d[nxt] == d[cv] && memo[nxt] > org)
                    memo[nxt] = org;
            } else if(s[cv] != '1') {
                if(d[nxt] > d[cv] + 1){
                    d[nxt] = d[cv] + 1;
                    memo[nxt] = cv;
                    assert(nxt > cv);
                    que.emplace(d[nxt],nxt,cv);
                } else if(d[nxt] == d[cv] && memo[nxt] > cv){
                    memo[nxt] =  cv;
                }
            }
        }
    }
    vector<string> ans;
    int cpos = N;
    while(cpos != 0){
        ans.push_back(to_string(cpos - memo[cpos]));
        cpos = memo[cpos];
    }
    //cout << (d[N] == inf ? -1 : d[N]) << endl;
    if(d[N] != inf){
        reverse(ans.begin(),ans.end());
        for(auto s : ans)
            cout << s << endl;
    } else {
        puts("-1");
    }
}



Compiler output:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::tuple<long long int, long long int, long long int>; _Args = {int, int}; _Tp = std::tuple<long long int, long long int, long long int>]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::tuple<long long int, long long int, long long int>; _Args = {int, int}; _Tp = std::tuple<long long int, long long int, long long int>; allocator_type = std::allocator<std::tuple<long long int, long long int, long long int> >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int, int}; _Tp = std::tuple<long long int, long long int, long long int>; _Alloc = std::allocator<std::tuple<long long int, long long int, long long int> >; reference = std::tuple<long long int, long long int, long long int>&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:754:18:   required from 'void std::priority_queue<_Tp, _Sequence, _Compare>::emplace(_Args&& ...) [with _Args = {int, int}; _Tp = std::tuple<long long int, long long int, long long int>; _Sequence = std::vector<std::tuple<long long int, long long int, long long int> >; _Compare = std::greater<void>]'
  754 |           c.emplace_back(std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:18:16:   required from here
   18 |     que.emplace(0,0);
      |     ~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'std::tuple<long long int, long long int, long long int>::tuple(int, int)'
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:1646:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<long long int, long long int, long long int>::_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Args2 ...>&&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {long long int, long long int, long long int}]'
 1646 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1646:9: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/tuple:1634:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<long long int, long long int, long long int>::_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Args2 ...>&&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {long long int, long long int, long long int}]'
 1634 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1634:9: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/tuple:1623:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<long long int, long long int, long long int>::_TCC<_Valid>::__is_explicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Args2 ...>&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> = _Valid; _Elements = {long long int, long long int, long long int}]'
 1623 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1623:9: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/tuple:1611:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<long long int, long long int, long long int>::_TCC<_Valid>::__is_implicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Args2 ...>&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> = _Valid; _Elements = {long long int, long long int, long long int}]'
 1611 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1611:9: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/tuple:1603:9: note: candidate: 'template<class _Alloc> std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, std::tuple< <template-parameter-1-1> >&&) [with _Elements = {long long int, long long int, long long int}]'
 1603 |         tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:1603:9: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/tuple:1598:9: note: candidate: 'template<class _Alloc> std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple< <template-parameter-1-1> >&) [with _Elements = {long long int, long long int, long long int}]'
 1598 |         tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:1598:9: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/tuple:1591:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<long long int, long long int, long long int>::_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, _UElements&& ...) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {long long int, long long int, long long int}]'
 1591 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1591:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/tuple:1587:59: error: no matching function for call to 'std::tuple<long long int, long long int, long long int>::__valid_args<>()'
 1587 |                  bool _Valid = __valid_args<_UElements...>(),
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/include/c++/14/tuple:1390:31: note: candidate: 'template<class _Up> static constexpr bool std::tuple< <template-parameter-1-1> >::__valid_args() [with _Elements = {long long int, long long int, long long int}]'
 1390 |         static constexpr bool __valid_args()
      |                               ^~~~~~~~~~~~
/usr/include/c++/14/tuple:1390:31: note:   template argument deduction/substitution failed:
/usr/include/c++/14/tuple:1587:59: note:   couldn't deduce template parameter '_Up'
 1587 |                  bool _Valid = __valid_args<_UElements...>(),
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/include/c++/14/tuple:1398:31: note: candidate: 'template<class, class, class ... _Tail> static constexpr bool std::tuple< <template-parameter-1-1> >::__valid_args() [with _Tail = <template-parameter-1-1>; _Elements = {long long int, long long int, long long int}]'
 1398 |         static constexpr bool __valid_args()
      |                               ^~~~~~~~~~~~
/usr/include/c++/14/tuple:1398:31: note:   template argument deduction/substitution failed:
/usr/include/c++/14/tuple:1587:59: note:   couldn't deduce template parameter '<template-parameter-1-1>'
 1587 |                  bool _Valid = __valid_args<_UElements...>(),
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/include/c++/14/tuple:1581:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<long long int, long long int, long long int>::_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, _UElements&& ...) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {long long int, long long int, long long int}]'
 1581 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1581:9: note:   template a