def solution(id_list, report, k):
user = []
warning = []
out = []
user_dict = {}
warning_dict = {}
answer = []
for i in id_list:
user_dict[i] = 0
for i in list(set(report)):
warning.append(i.split()[1])
for i in warning:
try: warning_dict[i] += 1
except: warning_dict[i] = 1
for key, value in warning_dict.items():
if k <= value:
out.append(key)
for i in list(set(report)):
for j in out:
if j in i.split()[1]:
user.append(i.split()[0])
for i in user:
try: user_dict[i] += 1
except: user_dict[i] = 1
for key, value in user_dict.items():
answer.append(value)
return answer
^^...
채점 결과 점수가 최악이다...
시간 제한(1시간)을 초과해서까지 작성한 코드인데 장렬히 탈락.
def solution(id_list, reports, k):
answer = [0] * len(id_list)
stop = []
dict = {id: [] for id in id_list}
for i in set(reports):
report = i.split(' ')
stop.append(report[1])
dict[report[0]].append(report[1])
stop = set([i for i in stop if stop.count(i) >= k])
for key, value in dict.items():
for s in stop:
if s in value:
answer[id_list.index(key)] += 1
return answer
시간초과로인한 실패
def solution(id_list, reports, k):
answer = [0] * len(id_list)
dict = {id: 0 for id in id_list}
for i in set(reports):
dict[i.split()[1]] += 1
for i in set(reports):
if dict[i.split()[1]] >= k:
answer[id_list.index(i.split()[0])] += 1
return answer
dict = {id: 0 for id in [1,2,3]}
> {1: 0, 2: 0, 3: 0}