Problem: Takahashi is playing a board game called Sugoroku.  On the board, there are N + 1 squares numbered 0 to N. Takahashi starts at Square 0, and he has to stop exactly at Square N to win the game.  The game uses a roulette with the M numbers from 1 to M. In each turn, Takahashi spins the roulette. If the number x comes up when he is at Square s, he moves to Square s+x. If this makes him go beyond Square N, he loses the game.  Additionally, some of the squares are Game Over Squares. He also loses the game if he stops at one of those squares. You are given a string S of length N + 1, representing which squares are Game Over Squares. For each i (0 \leq i \leq N), Square i is a Game Over Square if S[i] = 1 and not if S[i] = 0.  Find the sequence of numbers coming up in the roulette in which Takahashi can win the game in the fewest number of turns possible. If there are multiple such sequences, find the lexicographically smallest such sequence. If Takahashi cannot win the game, print -1.

Submission attempts (in order):
from sys import stdin



def input():
	return stdin.readline().strip()

from collections import deque

n, m = map(int, input().split())

s = input()

def bfs(src):
	que = deque([[src, []]])
	visited = {src, }

	while que:
		u, path = que.popleft()
		if u == 0:
			return path
		for i in range(m, 0, -1):
			next_pos = u - i
			if next_pos not in visited and next_pos >= 0 and s[next_pos]=='0':
				visited.add(next_pos)
				que.append((next_pos, path+[i]))
	return -1

ans = bfs(n)
if ans == -1:
	print(ans)
else:
	print(*ans)

from sys import stdin
sys.setrecursionlimit(pow(10, 9))



def input():
	return stdin.readline().strip()

from collections import deque

n, m = map(int, input().split())

s = input()

def bfs(src):
	que = deque([[src, []]])
	visited = {src, }

	while que:
		u, path = que.popleft()
		if u == n:
			return path
		for i in range(1, m+1):
			next_pos = u + i
			if next_pos not in visited and next_pos <= n and s[next_pos]=='0':
				visited.add(next_pos)
				que.append((next_pos, path+[i]))
	return -1

ans = bfs(0)
if ans == -1:
	print(ans)
else:
	print(*ans)

from sys import stdin



def input():
	return stdin.readline().strip()

from collections import deque

n, m = map(int, input().split())

s = input()

def bfs(src):
	que = deque([[src, []]])
	visited = {src, }

	while que:
		u, path = que.popleft()
		if u == 0:
			return path
		for i in range(m, 0, -1):
			next_pos = u - i
			if next_pos not in visited and next_pos <= n and s[next_pos]=='0':
				visited.add(next_pos)
				que.append((next_pos, path+[i]))
	return -1

ans = bfs(n)
if ans == -1:
	print(ans)
else:
	print(*ans)

from sys import stdin



def input():
	return stdin.readline().strip()

from collections import deque

n, m = map(int, input().split())

s = input()

def bfs(src):
	que = deque([[src, []]])
	visited = {src, }

	while que:
		u, path = que.popleft()
		if u == n:
			return path
		for i in range(m, 0, -1):
			next_pos = u + i
			if next_pos not in visited and next_pos <= n and s[next_pos]=='0':
				visited.add(next_pos)
				que.append((next_pos, path+[i]))
	return -1

ans = bfs(0)
if ans == -1:
	print(ans)
else:
	print(*ans)

N, M = map(int, input().split())
S = input().strip()
T = S[::-1]

l = []
i = 0
while i < N:
  t = T[i+1: i+M+1][::-1]
  if '0' not in t:
    print(-1)
    exit()
  else:
    x = min(M - t.index('0'), len(t))
    l.append(x)
    i += x
print(*l[::-1])

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted