Coding Test/softeer

[소프티어] 스마트 물류- python (레벨 3)

조용장 2022. 5. 13. 20:55

https://softeer.ai/practice/info.do?eventIdx=1&psProblemId=414 

 

Softeer

연습문제를 담을 Set을 선택해주세요. 취소 확인

softeer.ai

풀이

문제를 보았을때 알수있는 힌트

문제를 보고 dp 문제라고 생각하고 접근하였다. p의 로봇의 위치는 dp에 True로 변경하고 k만큼 왼쪽에서 오른쪽으로 dp가 False인 경우에 dp를 True로 바꾸면서 count를 1씩 증가시키면 끝이 나는 문제이다.

 

input= sys.stdin.readline

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

dp = [False]*n

n_list = list(input().strip())

# print(n_list)

for i in range(len(n_list)):
    if n_list[i]=='P':
        dp[i]=True

# print(dp)
count=0
for i in range(len(n_list)):
    if n_list[i]=='P':
        for j in range(i-k,i+k+1):
            if j>=0 and j<n and dp[j]==False and n_list[j]=="H":
                dp[j]=True
                count+=1
                break
# print(dp)
print(count)

https://github.com/dydwkd486/coding_test/blob/main/softeer/스마트%20물류.py 

 

GitHub - dydwkd486/coding_test: 코딩테스트 공부한 내용 정리

코딩테스트 공부한 내용 정리. Contribute to dydwkd486/coding_test development by creating an account on GitHub.

github.com