백준 19941번

DARTZ·2023년 4월 4일
0

알고리즘

목록 보기
106/135
import sys

sys.stdin = open("input.txt", "r")

N, M = map(int, sys.stdin.readline().split())
table = list(sys.stdin.readline())

def solution(N, M, table):

    count = 0

    for i in range(N):
        if table[i] == "P":
            minRange = max(0, i - M)
            maxRange = min(N, i + M + 1)

            for k in range(minRange, maxRange):
                if table[k] == "H":
                    table[k] = "X"
                    count += 1
                    break

    return count


print(solution(N, M, table))
profile
사람들이 비용을 지불하고 사용할 만큼 가치를 주는 서비스를 만들고 싶습니다.

0개의 댓글