Problem:


Score : 600 points

Problem Statement

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.

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^5

|S| = N + 1

S consists of 0 and 1.

S[0] = 0

S[N] = 0

Input

Input is given from Standard Input in the following format:

N M
S

Output

If Takahashi can win the game, print the lexicographically smallest sequence among the shortest sequences of numbers coming up in the roulette in which Takahashi can win the game, with spaces in between.

If Takahashi cannot win the game, print -1.

Sample Input 1

9 3
0001000100

Sample Output 1

1 3 2 3

If the numbers 1, 3, 2, 3 come up in this order, Takahashi can reach Square 9 via Square 1, 4, and 6. He cannot reach Square 9 in three or fewer turns, and this is the lexicographically smallest sequence in which he reaches Square 9 in four turns.

Sample Input 2

5 4
011110

Sample Output 2

-1

Takahashi cannot reach Square 5.

Sample Input 3

6 6
0101010

Sample Output 3

6



Sample input:
9 3
0001000100


Sample output:
1 3 2 3

Submission status: Wrong Answer

Solution code:
import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
s = input()
ind = n
ls = []
while ind > 0:
    for i in range(min(m, ind), 0, -1):
        if s[ind - i] == "0":
            ind -= i
            break
        i = -1
        ind = 0
        break
    ls.append(str(i))
print(" ".join(ls[::-1]))

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    S = input()[::-1]
    
    ans = []
    i = 0
    
    if S[0] == '1': print(-1); sys.exit()
    
    while i < N:
        for j in range(min(M,N-i), 0, -1):
            if  S[i+j] == '0': break
        else: print(-1); sys.exit()
        
        ans.append(j)
        i += j
        
    for a in ans[::-1]: print(a)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    S = input()[::-1]
    
    ans = []
    i = 0
    
    if S[0] == '1': print(-1); sys.exit()
    
    while i < N:
        for j in range(min(M,N-i), 0, -1):
            if  S[i+j] == '0': break
        else: print(-1); sys.exit()
        
        ans.append(j)
        i += j
        
    print(' '.join(map(str, ans[::-1])))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

  ans = []
  i = 0

  if S[0] == '1': print(-1); sys.exit()

  while i < N:
      f = True
      for j in range(M, 0, -1):
          if i+j > N: f = False
          elif S[i+j] == '0': break
      else: print(-1); sys.exit()

      ans.append(j)
      i += j

      if not f: break

  print(*ans[::-1])
    
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

  ans = []
  i = 0

  if S[0] == '1': print(-1); sys.exit()

  while i < N:
      f = True
      for j in range(M, 0, -1):
          if i+j > N: f = False
          elif S[i+j] == '0': break
      else: print(-1); sys.exit()

      ans.append(j)
      i += j

      if not f: break

  for a in ans[::-1]: print(a, '', end='')
    
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

  ans = []
  i = 0

  if S[0] == '1': print(-1); sys.exit()

  while i < N:
      f = True
      for j in range(M, 0, -1):
          if i+j > N: f = False
          elif S[i+j] == '0': break
      else: print(-1); sys.exit()

      ans.append(j)
      i += j
      if not f: break

  print(' '.join(map(str, ans[::-1])))
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
S = list(input())[:-1]
cur = n
ans = ""
while cur:
	s = S[max(0,cur-m):cur]
	# print(s)
	try:
		idx = min(m,len(s))-s.index("0")
	except ValueError:
		ans = -1
		break
	# print(S[:cur])
	ans += str(idx)
	cur -= idx
	# print(ans)
print(*ans[::-1]) if ans != -1 else print(-1)

Submission status: Wrong Answer

Solution code:
N, M = [int(item) for item in input().split()]
S = input()
a=[]
s = S
n = N
while n > 0:
    if n<=M and s[0] == '0':
        a.append(n)
        break
    for i in range(M, 0, -1):
        can = False
        if n>=i and s[n-i] == '0':
            a.append(i)
            s = s[:n-i+1]
            n = n-i
            can = True
            break
    if not can and len(s)>1:
        print(-1)
        break
a=a[-1::-1]
if len(a):
    print(*a)

Submission status: Wrong Answer

Solution code:
N, M = [int(item) for item in input().split()]
S = input()
a=[]
s = S
n = N
while len(s)>1:
    for i in range(M, 0, -1):
        can = False
        if n<=i and s[0] == '0':
            a.append(i)
            s = ''
            break
        if n>=i and s[n-i] == '0':
            a.append(i)
            s = s[:n-i+1]
            n = n-i
            can = True
            break
    if not can and len(s)>1:
        print(-1)
        break
a=a[-1::-1]
if len(a):
    print(*a)

Submission status: Wrong Answer

Solution code:
N, M = [int(item) for item in input().split()]
S = input()
a=[]
s = S
n = N
while len(s)>1:
    if N<=M and s[0] == 0:
        a.append(M)
        break
    for i in range(M, 0, -1):
        can = False
        if n>=i and s[n-i] == '0':
            a.append(i)
            s = s[:n-i+1]
            n = n-i
            can = True
            break
    if not can and len(s)>1:
        print(-1)
        break
a=a[-1::-1]
if len(a):
    print(*a)

Submission status: Wrong Answer

Solution code:
N, M = [int(item) for item in input().split()]
S = input()
a=[]
s = S
n = N
while len(s)>1:
    if N<=M:
        a.append(M)
        break
    for i in range(M, 0, -1):
        can = False
        if n>=i and s[n-i] == '0':
            a.append(i)
            s = s[:n-i+1]
            n = n-i
            can = True
            break
    if not can and len(s)>1:
        print(-1)
        break
a=a[-1::-1]
if len(a):
    print(*a)

Submission status: Wrong Answer

Solution code:
N, M = [int(item) for item in input().split()]
S = input()
a=[]
s = S
n = N
while len(s)>1:
    for i in range(M, 0, -1):
        can = False
        if n>=i and s[n-i] == '0':
            a.append(i)
            s = s[:n-i+1]
            n = n-i
            can = True
            break
    if not can and len(s)>1:
        print(-1)
        break
a=a[-1::-1]
if len(a):
    print(*a)

Submission status: Wrong Answer

Solution code:
n,m = [int(i) for i in input().split()]
s = input()
d = 0
p = n
q = []

while p!=0:
    frag = True
    for i in range(max(p-m,0),p):
        if s[i]=='0':
            d+=1
            q.append(p-i)
            p=i
            frag = False
            break
    if frag:
        print(-1)
        break

        
for i in reversed(q):
    print(i)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

Submission status: Wrong Answer

Solution code:
def p_f_2():
    n, m = map(int, input().split())
    *s, = map(int, input())
    i = 0
    ans = []
    while i + m < n:
        for j in reversed(range(i + 1, i + m + 1)):
            if s[j] == 0:
                ans.append(j - i)
                i = j
                break
        else:
            print(-1)
            exit()
    ans.append(n-i)
    print(*ans)

if __name__ == '__main__':
    p_f_2()

Submission status: Wrong Answer

Solution code:
def p_f():
    n, m = map(int, input().split())
    *s, = map(int, input())
    dp = [10 ** 5 + 1] * (n + 1)
    dp[0] = 0
    tr = [[] for _ in range(n + 1)]
    for i in range(1, n + 1):
        k = max(0, i - m)
        for j in range(k, i):
            if s[i] == 1:
                continue
            if dp[i] > dp[j] + 1:
                dp[i] = dp[j] + 1

    print(dp)


if __name__ == '__main__':
    p_f()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N,M=map(int, sys.stdin.readline().split())
S=sys.stdin.readline().strip()

L=[]    #答えの集合
i=N
end=False
for _ in range(N/2):
    if end: break
    for m in range(M,-1,-1):
        #print m,i+m
        if 0<=i-m and S[i-m]=="0":
            L.append(m)
            i-=m
            if i==0: end=True
            break
        
if i!=0:
    print -1
else:
    print " ".join(map(str,L[::-1]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N,M=map(int, sys.stdin.readline().split())
S=sys.stdin.readline().strip()

L=[]    #答えの集合
i=N
end=False
for _ in range(N):
    if end: break
    for m in range(M,-1,-1):
        #print m,i+m
        if 0<=i-m and S[i-m]=="0":
            L.append(m)
            i-=m
            if i==0: end=True
            break
        
if sum(L)==0:
    print -1
else:
    print " ".join(map(str,L[::-1]))

Submission status: Wrong Answer

Solution code:
def main():    
    N, M = map(int, input().split())
    S = input()
    p = N
    a = []
    while p > 0:
        for i in range(min(M, p), 0, -1):
            if S[p - i] == '0':
                p = p - i
                a.append(str(i))
                break
        else:
            return -1
    return ''.join(i for i in reversed(a))
print(main())

Submission status: Wrong Answer

Solution code:
# 2019/11/30
from bisect import bisect_left

n,m=map(int,input().split())
s=list(input())[::-1]

mz=[i for i,e in enumerate(s) if e=='0']
ans=[]

def nbtn(key):
    idx=bisect_left(mz,key)
    if idx>=len(mz):return mz[-1]
    if mz[idx]==key:
        res=mz[idx]
    else:
        res=mz[idx-1]
    return res


i=0
key=m
while i<=len(mz):
    key=nbtn(key)
    res=key-i
    if res==0:
        if i+1==len(mz):break
        else:
            print(-1)
            exit()
    ans.append(res)
    i=key
    key+=m
print(*ans[::-1],sep=' ')

Submission status: Wrong Answer

Solution code:
# 2019/11/30
from bisect import bisect_left

n,m=map(int,input().split())
s=list(input())[::-1]

mz=[i for i,e in enumerate(s) if e=='0']
ans=[]

def nbtn(key):
    idx=bisect_left(mz,key)
    if idx>=len(mz):return mz[-1]
    if mz[idx]==key:
        res=mz[idx]
    else:
        res=mz[idx-1]
    return res


i=0
key=m
while i<len(mz):
    key=nbtn(key)
    res=key-i
    if res==0:
        print(-1)
        exit()
    ans.append(res)
    i=key
    key+=m

print(*ans[::-1],sep=' ')

Submission status: Wrong Answer

Solution code:
# 2019/11/30
from bisect import bisect_left

n,m=map(int,input().split())
s=list(input())[::-1]

mz=[i for i,e in enumerate(s) if e=='0']
ans=[]

def nbtn(key):
    idx=bisect_left(mz,key)
    if idx>=len(mz):return mz[-1]
    if mz[idx]==key:
        res=mz[idx]
    else:
        res=mz[idx-1]
    return res


i=0
key=m
while i<len(mz)+1:
    key=nbtn(key)
    res=key-i
    if res==0:
        print(-1)
        exit()
    ans.append(res)
    i=key
    key+=m

print(*ans[::-1],sep=' ')

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M=map(int,input().split())
S=input()
j=N
ans=deque()
while j>0:
    for i in range(M,0,-1):

        if j-i==0:
            ans.appendleft(i)
            print(*ans)

        elif j-i<0:
            continue
        if S[j-i]=="0":
            ans.appendleft(i)
            j-=i

        if i==1 and S[j-i]=="1":
            print(-1)
            exit()

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M=map(int,input().split())
S=input()
j=N
ans=deque()
while j>0:
    for i in range(M,0,-1):

        if j-i==0:
            ans.appendleft(i)
            print(*ans)

        elif j-i<0:
            continue
        if S[j-i]=="0":
            ans.append(i)
            j-=i

        if i==1 and S[j-i]=="1":
            print(-1)
            exit()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

N, M = map(int, input().split())
S = input()

inf = 10**6
info = [0 for j in range(N+1)]

num = 0
q = []
heappush(q, (0, 0))
for i in range(1, N+1):
    if S[i] == '1':
        heappush(q, (inf, i))
    else:
        if i - q[0][1] <= M:
            info[i] = q[0][0] + 1
            heappush(q, (q[0][0] + 1, i))
        else:
            while i - q[0][1] > M:
                a, b = heappop(q)
            if q:
                info[i] = q[0][0] + 1
                heappush(q, (q[0][0]+1, i))

if info[N] > inf:
    print(-1)
    exit()

node = []
MIN = 0
for i in range(N+1):
    if info[i] == MIN:
        node.append(i)
        MIN += 1

if node[-1] != N:
    node[-1] = N
    
ans = []
left = node[0]
for i in range(1, len(node)):
    ans.append(node[i]-left)
    left = node[i]

output = ''
for i in ans:
    output += str(i) + ' '

print(output)

Submission status: Wrong Answer

Solution code:
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N, M = map(int, input().split())
S = input()

rS = [i for i in reversed(S)]
res = []
step = 0

lenS = len(S)
while 1:
    if step == lenS-1:
        break
    for i in range(M, -1, -1):
#        print(' i:', i)
        if step+i > lenS-1:
            continue
        if i == 0:
#            print(-1)
            exit()
        if rS[step+i] == '0':
#            print('step+', i)
            step += i
            res.append(i)
            break

print(*reversed(res))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
S=input()
L=[]
P=0

import sys
while P<N:
    k=0
    for i in range(1,M+1):
        if P+i>N:
            break
        if S[P+i]=='0':
            k=i
    if k==0:
        print(-1)
        sys.exit()
    L.append(k)
    P+=k
    
print(*L)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
S = input()

# dp[i] := ゴールから最短何手でマスiにたどり着けるか
dp = [float('inf')] * (N + 1)
dp[-1] = 0


class RangeMinimumQuery:
    def __init__(self, n, inf=2 ** 31 - 1):
        self.n = 1 << (n - 1).bit_length()
        self.INF = inf
        self.segtree = [self.INF] * (2 * self.n)

    # i番目の値(0-indexed)をxに変更
    def update(self, i, x):
        i += self.n
        self.segtree[i] = x
        while i > 0:
            i //= 2
            self.segtree[i] = min(self.segtree[2 * i], self.segtree[2 * i + 1])

    # [l, r)のmin
    def query(self, l, r):
        L, R = l + self.n, r + self.n
        R = min(R, self.n + 1)
        s = self.INF
        while L < R:
            if L & 1:
                s = min(s, self.segtree[L])
                L += 1

            if R & 1:
                s = min(s, self.segtree[R - 1])
                R -= 1

            L >>= 1
            R >>= 1

        return s


# セグメント木でdpテーブルを高速に埋める
RMQ = RangeMinimumQuery(N + 1)
RMQ.update(N, 0)
for i in range(N - 1, -1, -1):
    if S[i] == '1':
        continue

    # RMQ.query(l, r) := [l, r)の最小値
    dp[i] = RMQ.query(i, i + M + 1) + 1
    RMQ.update(i, dp[i])


ans = []
position = 0
while position < N:
    for move in range(1, M + 1):
        if position + move > N:
            continue

        if S[position + move] == '1':
            continue

        # 最短手数にならない
        if dp[position + move] == dp[position]:
            continue

        ans.append(move)
        position += move
        break

    else:
        print(-1)
        exit()

print(*ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
S,r,s=input(),[],N
for _ in range(2*N):
    if S[s]=='1':
        s += 1
    else:
        r.append(str(N-s))
        N,s=s,max(0,s-M)
print(-1 if s else " ".join(r[::-1]).strip('0 '))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
S,r,s=input(),[],N
for _ in range(N+1):
    if S[s]=='1':
        s += 1
    else:
        r.append(str(N-s))
        N,s=s,max(0,s-M)
print(-1 if s else " ".join(r[::-1]).strip('0 '))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
S,r,s=input(),[],N
for _ in range(N):
    if S[s]=='1':
        s += 1
    else:
        r.append(str(N-s))
        N,s=s,max(0,s-M)
print(-1 if s else " ".join(r[::-1]).strip('0 '))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
S,r,s=input(),"",N
exec("N,s,r=(s,max(0,s-M),'%d %s'%(N-s,r)) if S[s]=='0' else (N,s+1,r);"*N)
print(-1 if s else r.strip('0 '))

Submission status: Wrong Answer

Solution code:
"""
Beginners Contests 146
F - Sugoroku
https://atcoder.jp/contests/abc146/tasks/abc146_f
"""
from collections import deque
import copy
N, M = map(int, input().split())
S = input()
len_s = len(S)
# initialize
queue = deque([[0]])
ans = []
end_flg = False
distance_to_goal = N
while len(queue) > 0:
    m = M
    # print("queue contents are {}".format(queue))
    here = queue.popleft()
    # print(end_flg)
    # print("ans:{}".format(ans))
    if end_flg and len(ans[0]) == len(here):
        answer = ans[-1]
        answer.pop(0)
        print(' '.join(map(str, answer)))
        quit()

    # print("this queue is {}".format(here))
    # Get distance from start to here
    distance_from_start = sum(here)
    distance_to_goal = N - distance_from_start
    # print("distance_from_start:{0},N:{1},distance_to_goal:{2}".format(distance_from_start, N, distance_to_goal))
    # print("m:{}".format(m))
    if distance_to_goal < m:
        m = distance_to_goal
    for i in range(m, 0, -1):
        tmp_here = copy.copy(here)
        # print("step count: {}".format(i))
        # print(S)
        # print("here step is {0}, char is {1} ".format(distance_from_start, S[distance_from_start]))

        # print("next step is {0} next char is {1}".format(str(distance_from_start + i), S[distance_from_start + i]))
        if distance_from_start + i == N:
            # When next place to be Goal !!!
            # print("answer was found")
            tmp_here.append(i)
            ans.append(tmp_here)
            end_flg = True
        # When place not to be game over
        elif S[distance_from_start + i] != "1":
            # print("tmp_here:{0}, i:{1}".format(tmp_here, i))
            tmp_here.append(i)
            # print("append next queue:{0}".format(tmp_here))
            queue.append(tmp_here)
#        else:
#            print("next step will be game over X(")
print('-1')

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
def solve():
  n,m = (int(i) for i in input().split())
  s = input()
  if n<= m:
    print(n)
    exit()
  tmp = 0
  for i in range(n+1):
    if s[i] =="1":
      tmp += 1
    else:
      tmp = 0
    if tmp >= m:
      print(-1)
      exit()
  s = s[::-1]
  query = deque([(0,"")])
  while query:
    place,mode = query.popleft()
    if place == n:
      break
    
    for i in range(1,m+1):
      if i+place >= n+1:
        break
      if s[i+place] != "1":
        query.append((i+place,mode+str(i)))
  tmp = []
  for i in range(len(mode)):
    tmp.append(mode[i])
    
  print(*tmp)
solve()

Submission status: Wrong Answer

Solution code:
from sys import stdin

# stdin = open("testdata.txt", "r")

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)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
s = list(input())
s.reverse()
list1 = []
def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(n-mass)
    return 1
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(i)
      maze(mass+i,times+1)
      return 1
    elif i == 1:
      print(-1)
      exit()
  return 1

a = maze(0,0)
list1.reverse()
print(" ".join(map(str,list1)))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
s = list(input())
s.reverse()
list1 = []
def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(n-mass)
    return
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(i)
      maze(mass+i,times+1)
      return
    elif i == 1:
      print(-1)
      exit()
  return

maze(0,0)
list1.reverse()
print(" ".join(map(str,list1)))

Submission status: Wrong Answer

Solution code:
from sys import stdin

# stdin = open("testdata.txt", "r")

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)

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
list1 = []
s = list(input())
s.reverse()

def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(n-mass)
    return
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(i)
      maze(mass+i,times+1)
      return
    elif i == 1:
      print(-1)
      exit()
  return

maze(0,0)
list1.reverse()
print(" ".join(map(str,list1)))

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
list1 = []
s = list(input())
s.reverse()

def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(n-mass)
    return
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(i)
      maze(mass+i,times+1)
      return
    elif i == 1:
      print(-1)
      exit()

maze(0,0)
list1.reverse()
print(" ".join(map(str,list1)))

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
list1 = []
s = list(input())
s.reverse()

def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(n-mass)
    return 0
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(i)
      return maze(mass+i,times+1)
    elif i == 1:
      print(-1)
      exit()
      #return -1

maze(0,0)
list1.reverse()
print(" ".join(map(str,list1)))

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
list1 = []
s = list(input())
s.reverse()

def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(n-mass)
    return "FUCK" #times + 1
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(i)
      return maze(mass+i,times+1)
    elif i == 1:
      print(-1)
      exit()
      #return -1

bitch = maze(0,0)
list1.reverse()
print(" ".join(map(str,list1)))

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
list1 = []
s = list(input())
s.reverse()
def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(n-mass)
    return #times + 1
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(i)
      return maze(mass+i,times+1)
    elif i == 1:
      print(-1)
      exit()
      #return -1

maze(0,0)
list1.reverse()
for i in list1:
    print("{} ".format(i), end = "")

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
list1 = []
s = list(input())
s.reverse()

def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(n-mass)
    return #times + 1
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(i)
      return maze(mass+i,times+1)
    elif i == 1:
      print(-1)
      exit()
      #return -1

maze(0,0)
list1.reverse()
print(" ".join(map(str,list1)))

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
s = input()

if s.find('1' * m) != -1:
  print('-1')
  exit(0)

i = n
rans = []
flag=True
while flag:
  for j in range(m, 1 - 1, -1):
    if i - j == 0:
      flag=False
    if i - j >= 0 and s[i - j] == '0':
      prev_i = i
      i = i - j
      rans.append(prev_i - i)
  
print(' '.join(map(str,reversed(rans))))

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
s = input()

if s.find('1' * m) != -1:
  print('-1')
  exit(0)

i = n
ans = []
flag=True
while flag:
  for j in range(m, 1 - 1, -1):
    if i-j>=0 and s[i - j] == '0':
      prev_i = i
      i = i - j
      ans.append(prev_i - i)
      if i == 0:
        flag=False
  
print(' '.join(map(str,reversed(ans))))

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
s = input()

if s.find('1' * m) != -1:
  print('-1')
  exit(0)

i = n
ans = []
flag=True
while flag:
  for j in range(m, 1 - 1, -1):
    if i - j < 0:
      flag=False
    if i - j >= 0 and s[i - j] == '0':
      prev_i=i
      i = i - j
      ans.append(prev_i-i)
  
print(' '.join(map(str,reversed(ans))))

Submission status: Wrong Answer

Solution code:
n, m = [ int(v) for v in input().split() ]
s = input()
s = s[::-1]
ans_list = []
dp_list = [ 0 for i in range(n+1) ]
p = 0
q = 0

while p < n:
    jmax = 0

    for j in range(1,m+1):
        if p+j <= n:
            dp_list[p+j] = dp_list[j] + 1
            if s[p+j] == "0":
                q = p+j
                jmax = j

    if p == q:
        break
    p = q
    ans_list.append(jmax)


if ans_list:
    for i in reversed(ans_list):
        print(i)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n-1):
        a,b=inpm()
        a-=1
        b-=1
        g[a].append((b,i))
        g[b].append((a,i))
    return n,g
    
def main():
    n,m=inpm()
    s=list(input())
    s.reverse()
    ans = ''
    now = 0
    while True:
        key = 0
        for go in range(m,0,-1):
            if now+go>=n:
                x=n-now
                ans+=str(x)
                ans=list(ans)
                ans.reverse()
                print(' '.join(ans))
                return
            elif s[now + go]=='0':
                key = 1
                now+=go
                ans+=str(go)
                break
        if key == 0:
            print(-1)
            return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
S=input()
cur=0
can_points=[0]
while cur<N:
  point=cur
  for i in range(min(M,N-cur)):
    if int(S[cur+1+i])==0:
      point=cur+1+i
  if point==cur:
    break
  else:
    cur=point
    can_points.append(point)
if cur<N:
    print(-1)
else:
    l=[]
    for i in range(len(can_points)-1):
        l.append(str(can_points[i+1]-can_points[i]))
        l.append(' ')
    print(''.join(l))

Submission status: Wrong Answer

Solution code:
import sys
n,m=map(int,input().split())
s=input()
if n<=m:
    print(n)
    sys.exit()
lst=[[] for i in range(m)]
for i in range(1,m+1):
    if s[i]=="0":
        lst[i%m].append(str(i))
left=1
right=m+1
while left<n:
    if s[left]=="0" and lst[left%m]:
        while right<=n:
            if right-left<=m:
                if s[right]=="0":
                    lst[right%m]=lst[left%m][:]
                    lst[right%m].append(str(right-left))
                    if right==n:
                        print(*lst[right%m])
                        sys.exit()
                right+=1
            else:
                break
    left+=1
print(-1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s=input()

lst=[[] for i in range(n+1)]
for i in range(1,min(m,n)+1):
    if s[i]=="0":
        lst[i].append(str(i))
    right=i+1
left=1
while left<n:
    if s[left]=="0":
        while right<=n:
            if right-left<=m:
                if s[right]=="0":
                    lst[right]=lst[left][:]
                    lst[right].append(str(right-left))
                right+=1
            else:
                break
    left+=1
if lst[n]:
    print(*lst[n])
else:
    print(-1)