SSAFY
[swea 파이썬] 10761. 신뢰
주니코니
2024. 8. 18. 22:32
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXSVc1TqEAYDFAQT
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
풀다가 신뢰 다 잃음
그래도 해냄! 해냄! 해냄!
이해완료.하
def s(t):
arr = list(map(str, input().split()))
total_time = 0
#처음 블루 로봇과 오렌지 로봇의 시작점(위치), 최근 버튼 누르기까지의 시간
robots = {'B': [1,0], 'O':[1,0]}
for i in range(1,len(arr)-1,2):
#목표 위치 - 현재 위치(로봇이 가야할 거리)
robot_button_distance = abs(int(arr[i+1]) - robots[arr[i]][0])
#로봇에게 주어진 시간(총 시뮬레이션 시간 - 최근 내가 버튼 누르는 데 쓴 시간=>앞 로봇이 최근 버튼을 누르는 데 쓴 시간
robot_time = total_time - robots[arr[i]][1]
# 만약 로봇이 가야할 거리와 로봇에게 주어진 시간이 같거나, 보다 가야할 거리가 적다면
# 즉 주어진 시간 내 가야할 목적지에 와있다면
##(이미 이동을 마쳤기 때문
if robot_button_distance <= robot_time:
#그 자리에서 버튼을 누르기만 하면 된다.
total_time += 1
#그게 아니면
else:
#총 시뮬레이션 시간 = 여태 미션수행 시간 + 로봇이 가야할 거리 - 주어진 시간(이동을 했다고 치고) + 1(버튼 누르는 시간)
total_time += robot_button_distance-robot_time +1
#딕셔너리 새로 업데이트
robots[arr[i]] = [int(arr[i+1]),total_time]
print(f'#{t} {total_time}')
if __name__ == '__main__':
T = int(input())
for t in range(1,T+1):
s(t)