Language: C++

#include<bits/stdc++.h>
using Int = long long;
constexpr Int inf = 1e18;
int main(){
    int N,M; cin >> N >> M;
    std::string s; cin >> s;
    std::vector<std::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);
    }
    std::vector<Int>d(N + 1,inf);
    std::vector<Int>memo(N + 1,inf);
    std::priority_queue<std::tuple<Int, Int,Int>,std::vector<tuple<Int,Int,Int>>,std::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;
                }
            }
        }
    }
    std::vector<std::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){
        std::reverse(ans.begin(),ans.end());
        for(auto s : ans)
            cout << s << endl;
    } else {
        puts("-1");
    }
}



Compiler output:
a.cc: In function 'int main()':
a.cc:5:14: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    5 |     int N,M; cin >> N >> M;
      |              ^~~
      |              std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146,
                 from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:11:19: error: 'min' was not declared in this scope; did you mean 'std::min'?
   11 |         int nxt = min(N,i + M);
      |                   ^~~
      |                   std::min
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: 'std::min' declared here
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:16:62: error: 'tuple' was not declared in this scope; did you mean 'std::tuple'?
   16 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                              ^~~~~
      |                                                              std::tuple
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/stl_pair.h:92:11: note: 'std::tuple' declared here
   92 |     class tuple;
      |           ^~~~~
a.cc:16:76: error: wrong number of template arguments (3, should be at least 1)
   16 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                                            ^~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:428:11: note: provided for 'template<class _Tp, class _Alloc> class std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:16:79: error: template argument 2 is invalid
   16 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                                               ^~
a.cc:16:79: error: template argument 3 is invalid
a.cc:16:81: error: expected unqualified-id before ',' token
   16 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                                                 ^
a.cc:16:95: error: invalid declarator before '>' token
   16 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                                                               ^~
a.cc:17:5: error: 'que' was not declared in this scope
   17 |     que.emplace(0,0);
      |     ^~~
a.cc:22:9: error: 'tie' was not declared in this scope; did you mean 'std::tie'?
   22 |         tie(k,cv,org) = que.top(); que.pop();
      |         ^~~
      |         std::tie
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/tuple:2791:5: note: 'std::tie' declared here
 2791 |     tie(_Elements&... __args) noexcept
      |     ^~~
a.cc:48:23: error: 'to_string' was not declared in this scope; did you mean 'std::__cxx11::to_string'?
   48 |         ans.push_back(to_string(cpos - memo[cpos]));
      |                       ^~~~~~~~~
      |                       std::__cxx11::to_string
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:4421:3: note: 'std::__cxx11::to_string' declared here
 4421 |   to_string(long double __val)
      |   ^~~~~~~~~
a.cc:55:13: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   55 |             cout << s << endl;
      |             ^~~~
      |             std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:55:26: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   55 |             cout << s << endl;
      |                          ^~~~
      |                          std::endl
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~