1
+ # https://wikidocs.net/16 -> 딕셔너리로 원소 삭제
2
+ # del 딕셔너리[삭제하려는 키] -> O(1)
3
+ import math
4
+ def getCalculate (t , fees ): # 이때 t는 출차 - 입차 (소요시간)
5
+ if t <= fees [0 ]:
6
+ return fees [1 ]
7
+ else :
8
+ return fees [1 ] + (math .ceil ((t - fees [0 ]) / fees [2 ])) * fees [3 ]
9
+
10
+ def getTime (time ):
11
+ h , m = time .split (":" )
12
+ return int (h ) * 60 + int (m )
13
+
14
+ def solution (fees , records ):
15
+ answer = []
16
+ r = dict () # key = 차량이름, value = 시간, 입차/출차
17
+ ans = dict () # key = 차량이름 value = [총 주차시간, 돈]
18
+
19
+ for rr in records :
20
+ car = list (rr .split (' ' ))
21
+ if car [2 ] == "IN" :
22
+ time = getTime (car [0 ])
23
+ r [car [1 ]] = [time , car [2 ]]
24
+ elif car [2 ] == "OUT" :
25
+ if car [1 ] in r :
26
+ out_time = getTime (car [0 ])
27
+ money = getCalculate (out_time - r [car [1 ]][0 ], fees )
28
+ if car [1 ] in ans :
29
+ ans [car [1 ]] = [(out_time - r [car [1 ]][0 ]) + ans [car [1 ]][0 ], money ]
30
+ else :
31
+ ans [car [1 ]] = [out_time - r [car [1 ]][0 ], money ]
32
+ del r [car [1 ]]
33
+
34
+ # 입차만 하고 출차한 경우
35
+ for dummy_car in r :
36
+ out_time = getTime ("23:59" )
37
+ if dummy_car in ans :
38
+ money = getCalculate ((out_time - r [dummy_car ][0 ]) + ans [dummy_car ][0 ], fees )
39
+ ans [dummy_car ] = [out_time - r [dummy_car ][0 ], money ]
40
+ else :
41
+ money = getCalculate ((out_time - r [dummy_car ][0 ]), fees )
42
+ ans [dummy_car ] = [out_time - r [dummy_car ][0 ], money ]
43
+
44
+ a = sorted (ans , key = lambda x :x )
45
+ for k in a :
46
+ answer .append (ans [k ][1 ])
47
+ return answer
48
+
49
+ fees = [180 , 5000 , 10 , 600 ]
50
+ 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" ]
51
+ print (solution (fees , records ))
0 commit comments