Koala - 11기/기초 알고리즘 스터디
[백준/python3] 2852번: NBA농구
יוֹסֵף
2023. 8. 28. 12:55
https://www.acmicpc.net/problem/2852
2852번: NBA 농구
첫째 줄에 골이 들어간 횟수 N(1<=N<=100)이 주어진다. 둘째 줄부터 N개의 줄에 득점 정보가 주어진다. 득점 정보는 득점한 팀의 번호와 득점한 시간으로 이루어져 있다. 팀 번호는 1 또는 2이다. 득
www.acmicpc.net
문제
문제해석
1번과 2번팀이 48분의 경기동안 각 각 몇분간 이기고 있었는지 구하는 문제이다.
코드
goal = int(input())
team_one_score = 0
team_two_score = 0
team_one_time = 0
team_two_time = 0
time_score_dic = dict()
for _ in range(goal):
team, win_time = input().split()
m, s = map(int, win_time.split(":"))
time_score_dic[m * 60 + s] = int(team)
for i in range(48 * 60):
if i in time_score_dic:
if time_score_dic[i] == 1:
team_one_score += 1
else:
team_two_score += 1
if team_one_score > team_two_score:
team_one_time += 1
elif team_one_score < team_two_score:
team_two_time += 1
team_one_m = team_one_time // 60
team_one_s = team_one_time % 60
team_two_m = team_two_time // 60
team_two_s = team_two_time % 60
print("{:02d}:{:02d}".format(team_one_m, team_one_s))
print("{:02d}:{:02d}".format(team_two_m, team_two_s))
문제풀이
48분을 초로 계산하면 48 x 60이다. 이를 for문으로 구현해도 시간복잡도가 크지 않으므로 실시간으로 각 각의 팀이 이기고 있을 경우 1초를 더해주며 시간을 계산을 해준다.