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):
def solve(mid):
    return c[ng-1]-c[mid-1]!=ng-mid
n,m=map(int,input().split())
*s,=map(int,input())
c=s[:]+[0]
for i in range(n):c[i+1]+=c[i]
a=[]
i=0
while i<=n:
    if n-i<=m:
        a+=n-i,
        break
    ok=i 
    ng=i+m+1 
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve(mid):
            ok=mid
        else:
            ng=mid
    a+=ok-i,
    if i==ok:
        print(-1)
        exit()
    i=ok
    #print(i)
print(*a)


def solve(mid):
    return c[ok]-c[mid]!=ok-mid
n,m=map(int,input().split())
*s,=map(int,input())
c=s[:]
for i in range(n-1):c[i+1]+=c[i]
a=[]
i=0
while i<=n:
    if n-i<=m:
        a+=n-i,
        break
    ok=i 
    ng=i+m+1 
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve(mid):
            ok=mid
        else:
            ng=mid
    a+=ok-i,
    if i==ok:
        print(-1)
        exit()
    i=ok
    #print(i)
print(*a)


def solve(mid):
    return c[ok]-c[mid]!=ok-mid
n,m=map(int,input().split())
*s,=map(int,input())
c=s[:]
for i in range(n-1):c[i+1]+=c[i]
a=[]
i=0
while i<=n:
    if n-i<=m:
        a+=n-i,
        break
    ok=i 
    ng=i+m+1 
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve(mid):
            ok=mid
        else:
            ng=mid
    a+=ok-i,
    if i==ok:
        print(-1)
        exit()
    i=ok
    print(i)
print(*a)

def solve(mid):
    return c[ng]-c[mid]!=ng-mid
n,m=map(int,input().split())
*s,=map(int,input())
c=[0]+s[:]
for i in range(n):c[i+2]+=c[i+1]
a=[]
i=0
while i<=n:
    if n-i<=m:
        a+=n-i,
        break
    ok=i 
    ng=i+m+1 
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve(mid):
            ok=mid
        else:
            ng=mid
    a+=ok-i,
    if i==ok:
        print(-1)
        exit()
    i=ok
    #print(i)
print(*a)

def solve(mid):
    return c[ng-1]-c[mid-1]!=ng-mid
n,m=map(int,input().split())
*s,=map(int,input())
c=s[:]+[0]
for i in range(n):c[i+1]+=c[i]
a=[]
i=0
while i<=n:
    if n-i<=m:
        a+=n-i,
        break
    ok=i 
    ng=i+m+1 
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve(mid):
            ok=mid
        else:
            ng=mid
    a+=ok-i,
    if i==ok:
        print(-1)
        exit()
    i=ok
    #print(i)
print(*a)

n,m=map(int,input().split())
*s,=map(int,input()[::-1])
i=0
a=[]
while i<n:
    j=min(n,i+m)
    while s[j]:j-=1
    if j==i:
        print(-1)
        exit()
    a+=j-i,
    i=j
print(*a[::-1])

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted