Language: C++

#include<iostream>
#include<algorithm>
#include<numeric>
#include<utility>
using Int = long long;
constexpr Int inf = 1e18;
int main(){
    int N,M; std::cin >> N >> M;
    std::string s; std::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 = std::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<std::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;
        std::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(std::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)
            std::cout << s << std::endl;
    } else {
        puts("-1");
    }
}



Compiler output:
a.cc: In function 'int main()':
a.cc:10:10: error: 'vector' is not a member of 'std'
   10 |     std::vector<std::vector<int>>edge(N + 1);
      |          ^~~~~~
a.cc:5:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    4 | #include<utility>
  +++ |+#include <vector>
    5 | using Int = long long;
a.cc:10:22: error: 'vector' is not a member of 'std'
   10 |     std::vector<std::vector<int>>edge(N + 1);
      |                      ^~~~~~
a.cc:10:22: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:10:29: error: expected primary-expression before 'int'
   10 |     std::vector<std::vector<int>>edge(N + 1);
      |                             ^~~
a.cc:11:28: error: 'edge' was not declared in this scope
   11 |     for(int i = 0; i + 1 < edge.size(); ++i)
      |                            ^~~~
a.cc:13:28: error: 'edge' was not declared in this scope
   13 |     for(int i = 0; i + 1 < edge.size(); ++i){
      |                            ^~~~
a.cc:17:10: error: 'vector' is not a member of 'std'
   17 |     std::vector<Int>d(N + 1,inf);
      |          ^~~~~~
a.cc:17:10: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:17:20: error: expected primary-expression before '>' token
   17 |     std::vector<Int>d(N + 1,inf);
      |                    ^
a.cc:17:21: error: 'd' was not declared in this scope
   17 |     std::vector<Int>d(N + 1,inf);
      |                     ^
a.cc:18:10: error: 'vector' is not a member of 'std'
   18 |     std::vector<Int>memo(N + 1,inf);
      |          ^~~~~~
a.cc:18:10: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:18:20: error: expected primary-expression before '>' token
   18 |     std::vector<Int>memo(N + 1,inf);
      |                    ^
a.cc:18:21: error: 'memo' was not declared in this scope
   18 |     std::vector<Int>memo(N + 1,inf);
      |                     ^~~~
a.cc:19:10: error: 'priority_queue' is not a member of 'std'
   19 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<std::tuple<Int,Int,Int>>,std::greater<>>que;
      |          ^~~~~~~~~~~~~~
a.cc:5:1: note: 'std::priority_queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
    4 | #include<utility>
  +++ |+#include <queue>
    5 | using Int = long long;
a.cc:19:49: error: expected primary-expression before ',' token
   19 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<std::tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                 ^
a.cc:19:55: error: 'vector' is not a member of 'std'
   19 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<std::tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                       ^~~~~~
a.cc:19:55: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:19:84: error: expected primary-expression before '>' token
   19 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<std::tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                                                    ^~
a.cc:19:86: error: expected primary-expression before ',' token
   19 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<std::tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                                                      ^
a.cc:19:100: error: expected primary-expression before '>' token
   19 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<std::tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                                                                    ^~
a.cc:19:102: error: 'que' was not declared in this scope
   19 |     std::priority_queue<std::tuple<Int, Int,Int>,std::vector<std::tuple<Int,Int,Int>>,std::greater<>>que;
      |                                                                                                      ^~~
a.cc:27:24: error: 'edge' was not declared in this scope
   27 |         for(auto nxt : edge[cv]){
      |                        ^~~~
a.cc:40:21: error: 'assert' was not declared in this scope
   40 |                     assert(nxt > cv);
      |                     ^~~~~~
a.cc:5:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    4 | #include<utility>
  +++ |+#include <cassert>
    5 | using Int = long long;
a.cc:48:10: error: 'vector' is not a member of 'std'
   48 |     std::vector<std::string> ans;
      |          ^~~~~~
a.cc:48:10: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:48:28: error: expected primary-expression before '>' token
   48 |     std::vector<std::string> ans;
      |                            ^
a.cc:48:30: error: 'ans' was not declared in this scope; did you mean 'abs'?
   48 |     std::vector<std::string> ans;
      |                              ^~~
      |                              abs