1import math
2
3def diff(start, end):
4 sh, sm = map(int, start.split(':'))
5 eh, em = map(int, end.split(':'))
6
7 return (eh*60+em) - (sh*60+sm)
8
9def calc(time, baseTime, baseFee, unitTime, unitFee):
10 if time < baseTime:
11 return baseFee
12 time -= baseTime
13 return baseFee + math.ceil(time/unitTime)*unitFee
14
15def solution(fees, records):
16 cars = {}
17 for i in records:
18 time, car_num, _ = i.split(' ')
19 # ์๋ก ์
์ฐจ ํ ๊ฒฝ์ฐ
20 if not car_num in cars:
21 cars[car_num] = [0, time]
22 else:
23 # ์ถ์ฐจ ํ ๋ค์ ์
์ฐจํ ๊ฒฝ์ฐ
24 if cars[car_num][1] == '':
25 cars[car_num][1] = time
26 # ์ถ์ฐจํ ๊ฒฝ์ฐ
27 else:
28 cars[car_num][0] += diff(cars[car_num][1], time)
29 cars[car_num][1] = ''
30
31 # ์์ง ์ถ์ฐจํ์ง ์์ ์ฐจ๋๋ค์ ๋ํด 23:59์ ์ถ์ฐจํ ๊ฒ์ผ๋ก ๊ฐ์ฃผ
32 for num in cars:
33 if cars[num][1] != '':
34 cars[num][0] += diff(cars[num][1], '23:59')
35 cars[num][1] = ''
36
37 # ์๊ธ ๊ณ์ฐ
38 for num in cars:
39 cars[num] = calc(cars[num][0], fees[0], fees[1], fees[2], fees[3])
40
41 # ์ฐจ๋ ๋ฒํธ ์์ผ๋ก ์ ๋ ฌ
42 sorted_keys = sorted(cars.keys())
43 # ์๊ธ๋ง ์ถ์ถํด์ ๋ฐํ
44 return [cars[key] for key in sorted_keys]
๋ฌธ์
- ๊ธฐ๋ณธ ์๊ฐ, ๊ธฐ๋ณธ ์๊ธ, ๋จ์ ์๊ฐ, ๋จ์ ์๊ธ
- ์ฐจ๋์ ์
์ถ์ฐจ ๊ธฐ๋ก (์๊ฐ(HH:MM), ์ฐจ๋๋ฒํธ(XXXX), ๋ด์ญ(์
์ฐจ/์ถ์ฐจ))
- ์ ์ ๋ณด๊ฐ ์ฃผ์ด์ง๋, ๊ฐ ์ฐจ๋๋ณ ์ฃผ์ฐจ ์๊ธ์ ๊ณ์ฐํด์ ์ฐจ๋๋ฒํธ ์์ผ๋ก ์ ๋ ฌํ์ฌ ๋ฐํํ๋ผ
- ์
์ฐจ๋ง ํ๊ณ ์ถ์ฐจํ์ง ์์ ์ฐจ๋์, 23:59์ ์ถ์ฐจํ ๊ฒ์ผ๋ก ๊ฐ์ฃผํ๋ค
- TC
- input
fees: [180, 5000, 10, 600]
records: [“05:34 5961 IN”, “06:00 0000 IN”, “06:34 0000 OUT”, “07:59 5961 OUT”, “07:59 0148 IN”, “18:59 0000 IN”, “19:09 0148 OUT”, “22:59 5961 IN”, “23:00 5961 OUT”]