729D - Sea Battle - CodeForces Solution


constructive algorithms greedy math *1700

Please click on ads to support us..

Python Code:

import sys
input = sys.stdin.readline
def mp():return list(map(int,input().split()))
def it():return int(input())
import math

mod=10**9+7

def solve():
    n,a,b,k=mp()
    s=input().strip()
    tmp,ans=0,[]
    for i in range(n):
        if s[i]=='1':
            tmp=0
        else:
            tmp+=1
            if tmp==b:
                ans.append(i+1)
                tmp=0
    ret=len(ans)-(a-1)
    print(ret)
    print(" ".join(map(str,ans[:ret])))

    return

if __name__ == '__main__':

                
                solve()


Comments

Submit
0 Comments
More Questions

13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division