๐น ํ๋ฐฐ ๋ฐฐ๋ฌ๊ณผ ์๊ฑฐํ๊ธฐ
1. ๋ฌธ์ ๋งํฌ
2023 KAKAO BLIND RECRUITMENT: ํ๋ฐฐ ๋ฐฐ๋ฌ๊ณผ ์๊ฑฐํ๊ธฐ
2. ์ฝ๋
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def solution(cap, n, deliveries, pickups):
answer = 0
# ๋ฐฐ์ด์ด ๋ชจ๋ 0์ธ ๊ฒฝ์ฐ
zero_list = [0] * n
if deliveries == pickups == zero_list:
return answer
while deliveries or pickups:
answer += max(len(deliveries), len(pickups))
d_limit, p_limit = cap, cap
while deliveries:
# ๋ฐฐ๋ฌ ๊ฐ๋ฅ, ๋ฐฐ๋ฌ ๋ถํ์ ์ง
if deliveries[-1] <= d_limit:
d_limit -= deliveries.pop()
# ๋ถ๋ถ ๋ฐฐ๋ฌ
else:
deliveries[-1] -= d_limit
break
while pickups:
# ํฝ์
๊ฐ๋ฅ, ํฝ์
๋ถํ์ ์ง
if pickups[-1] <= p_limit:
p_limit -= pickups.pop()
# ๋ถ๋ถ ํฝ์
else:
pickups[-1] -= p_limit
break
return answer * 2
์ ํ์ฑ
ํ ์คํธ 1 ใ ํต๊ณผ (0.01ms, 10.3MB) ํ ์คํธ 2 ใ ํต๊ณผ (0.00ms, 10.1MB) ํ ์คํธ 3 ใ ํต๊ณผ (0.02ms, 10.2MB) ํ ์คํธ 4 ใ ํต๊ณผ (0.01ms, 10.1MB) ํ ์คํธ 5 ใ ํต๊ณผ (0.03ms, 10.3MB) ํ ์คํธ 6 ใ ํต๊ณผ (0.02ms, 10.2MB) ํ ์คํธ 7 ใ ํต๊ณผ (0.46ms, 10.2MB) ํ ์คํธ 8 ใ ํต๊ณผ (1.24ms, 10.4MB) ํ ์คํธ 9 ใ ํต๊ณผ (5.51ms, 10.3MB) ํ ์คํธ 10 ใ ํต๊ณผ (4.17ms, 10.3MB) ํ ์คํธ 11 ใ ํต๊ณผ (3.61ms, 10.3MB) ํ ์คํธ 12 ใ ํต๊ณผ (2.89ms, 10.3MB) ํ ์คํธ 13 ใ ํต๊ณผ (1.15ms, 10.3MB) ํ ์คํธ 14 ใ ํต๊ณผ (1.31ms, 10.1MB) ํ ์คํธ 15 ใ ํต๊ณผ (21.60ms, 12.1MB) ํ ์คํธ 16 ใ ํต๊ณผ (1288.20ms, 12.1MB) ํ ์คํธ 17 ใ ํต๊ณผ (102.19ms, 12.2MB) ํ ์คํธ 18 ใ ํต๊ณผ (45.73ms, 12.1MB) ํ ์คํธ 19 ใ ํต๊ณผ (38.29ms, 12.2MB) ํ ์คํธ 20 ใ ํต๊ณผ (39.27ms, 12 MB)
3. ํด์ค
๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค.
๊ฐ์ฅ ๋ฉ๋ฆฌ ์๋ ์ง๋ถํฐ ํธ๋ญ ์ฉ๋๋งํผ ๋ฐฐ๋ฌ๊ณผ ํฝ์ ์ ์งํํ๋ค. ๋ฐฐ๋ฌ ํน์ ํฝ์ ์ด ๋ค ์๋ฃ๋ ์ง์ ์คํ์์ ์ ๊ฑฐํด๋ฒ๋ฆฐ๋ค.
์คํ์ ๊ธธ์ด๊ฐ ๋ฐฉ๋ฌธํด์ผํ๋ ๊ฐ์ฅ ๋จผ ๊ธธ์ด์ด๋ฏ๋ก ๋ฐฐ๋ฌ๊ณผ ํฝ์ ์ค ๋ ํฐ ๊ฐ์ ๋ํด์ค๋ค. (๋์ ๋์์ ์ด๋ฃจ์ด์ง๋ฏ๋ก)
๋ง์ง๋ง์ผ๋ก ์๋ณต์ ๊ณ์ฐํด์ผํ๋ฏ๋ก answer์ 2๋ฅผ ๊ณฑํด์ค๋ค.
This post is licensed under CC BY 4.0 by the author.