Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13-H0ngJu #181

Merged
merged 93 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
6d36a3d
2024-03-04
tgyuuAn Mar 4, 2024
1adc4bd
2024-03-04
pknujsp Mar 4, 2024
9fda614
2024-03-05 ์„์œ  ์‹œ์ถ”
MunbinLee Mar 5, 2024
fedd1cc
2024-03-05
H0ngJu Mar 5, 2024
3c92be6
test
H0ngJu Mar 5, 2024
c1f3ff7
2024-03-05
H0ngJu Mar 5, 2024
7e66693
Merge pull request #150 from AlgoLeadMe/37-Munbin-Lee
MunbinLee Mar 7, 2024
771fb24
2024-03-07
tgyuuAn Mar 7, 2024
e06b723
readme ์ˆ˜์ •
H0ngJu Mar 7, 2024
512b3bf
Merge pull request #151 from AlgoLeadMe/1-H0ngJu
H0ngJu Mar 7, 2024
0a0d51e
2024-03-07
H0ngJu Mar 7, 2024
94734e3
2024-03-08
pknujsp Mar 7, 2024
37805ad
2024-03-08
pknujsp Mar 7, 2024
a2861d9
2024-03-08 ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก
MunbinLee Mar 7, 2024
c9c076b
2024-03-10
H0ngJu Mar 10, 2024
ecf5ee0
2024-03-10
tgyuuAn Mar 10, 2024
dc35c20
Merge pull request #148 from AlgoLeadMe/41-tgyuuAn
tgyuuAn Mar 10, 2024
f77be4e
2024-03-13
H0ngJu Mar 13, 2024
d5e1b26
2024-03-13
tgyuuAn Mar 13, 2024
44fc5a3
Merge pull request #155 from AlgoLeadMe/38-Munbin-Lee
MunbinLee Mar 13, 2024
a69d572
2024-03-14 ๋ฌผ์•ฝ
MunbinLee Mar 13, 2024
84612f0
2024-03-16
H0ngJu Mar 16, 2024
ed9e5aa
2024-03-16
tgyuuAn Mar 16, 2024
94e034c
2024-03-19
pknujsp Mar 19, 2024
d1971b6
2024-03-19
H0ngJu Mar 19, 2024
e6187a1
2024-03-20
tgyuuAn Mar 19, 2024
d5b14ef
Merge branch 'main' into 42-tgyuuAn
tgyuuAn Mar 22, 2024
0c41f9e
Merge pull request #152 from AlgoLeadMe/42-tgyuuAn
tgyuuAn Mar 22, 2024
b484dfa
2024-03-22
H0ngJu Mar 22, 2024
a251e77
2024-03-22
tgyuuAn Mar 22, 2024
8c9453e
2024-03-22
pknujsp Mar 22, 2024
193f85c
Merge pull request #149 from AlgoLeadMe/37-pknujsp
pknujsp Mar 22, 2024
191a2e9
Merge branch 'main' into 43-tgyuuAn
MunbinLee Mar 24, 2024
6af8851
Merge branch 'main' into 44-tgyuuAn
MunbinLee Mar 24, 2024
7491076
Merge pull request #157 from AlgoLeadMe/43-tgyuuAn
tgyuuAn Mar 24, 2024
d8db55b
Merge branch 'main' into 44-tgyuuAn
tgyuuAn Mar 24, 2024
88a639e
Merge pull request #159 from AlgoLeadMe/44-tgyuuAn
tgyuuAn Mar 24, 2024
2f89d84
Merge branch 'main' into 45-tgyuuAn
tgyuuAn Mar 24, 2024
9f48183
Merge pull request #162 from AlgoLeadMe/45-tgyuuAn
tgyuuAn Mar 24, 2024
1ee7e98
Merge pull request #153 from AlgoLeadMe/2-H0ngJu
H0ngJu Mar 25, 2024
b13d92f
2024-03-25
pknujsp Mar 25, 2024
d46feb3
Merge branch 'main' into 3-H0ngJu
H0ngJu Mar 25, 2024
301cbcc
Merge pull request #156 from AlgoLeadMe/3-H0ngJu
H0ngJu Mar 25, 2024
865b02b
Merge branch 'main' into 4-H0ngJu
H0ngJu Mar 25, 2024
bc817de
Merge pull request #158 from AlgoLeadMe/4-H0ngJu
H0ngJu Mar 25, 2024
f24a636
Merge branch 'main' into 5-H0ngJu
H0ngJu Mar 25, 2024
4b04141
Merge pull request #161 from AlgoLeadMe/5-H0ngJu
H0ngJu Mar 25, 2024
268b920
2024-03-25
H0ngJu Mar 25, 2024
d593d25
2024-03-25
tgyuuAn Mar 26, 2024
cb2cfd9
Merge branch 'main' into 6-H0ngJu
H0ngJu Mar 27, 2024
b06f1cb
Merge pull request #164 from AlgoLeadMe/6-H0ngJu
H0ngJu Mar 27, 2024
30874a9
Merge branch 'main' into 7-H0ngJu
H0ngJu Mar 27, 2024
91b36eb
Merge pull request #166 from AlgoLeadMe/7-H0ngJu
H0ngJu Mar 27, 2024
05dbfff
2024-03-28
H0ngJu Mar 28, 2024
01fbdd4
2024-03-29
pknujsp Mar 29, 2024
4bb0d01
2024-03-29
tgyuuAn Mar 29, 2024
1c426f4
2024-04-01
tgyuuAn Apr 1, 2024
6511bd9
2024-04-03
pknujsp Apr 2, 2024
ef65e31
2024-04-03
H0ngJu Apr 3, 2024
27c0798
2024-04-07
H0ngJu Apr 7, 2024
4f2026e
2024-04-09
H0ngJu Apr 9, 2024
13a412a
Merge branch 'main' into 8-H0ngJu
H0ngJu Apr 11, 2024
318bf96
Merge pull request #170 from AlgoLeadMe/8-H0ngJu
H0ngJu Apr 11, 2024
9024ee4
2024-04-07
tgyuuAn Apr 8, 2024
e9416a4
Merge branch 'main' into 46-tgyuuAn
tgyuuAn Apr 22, 2024
92f8388
Merge pull request #165 from AlgoLeadMe/46-tgyuuAn
tgyuuAn Apr 22, 2024
b04c16c
Merge branch 'main' into 47-tgyuuAn
tgyuuAn Apr 22, 2024
124514a
Merge pull request #167 from AlgoLeadMe/47-tgyuuAn
tgyuuAn Apr 22, 2024
bfe4a47
Merge branch 'main' into 48-tgyuuAn
tgyuuAn May 3, 2024
a6ee561
Merge pull request #160 from AlgoLeadMe/39-Munbin-Lee
MunbinLee May 3, 2024
3c10fb8
Merge pull request #171 from AlgoLeadMe/48-tgyuuAn
tgyuuAn May 3, 2024
66ea60f
Merge pull request #154 from AlgoLeadMe/38-pknujsp
MunbinLee May 3, 2024
83f9c41
Merge pull request #163 from AlgoLeadMe/39-pknujsp
MunbinLee May 3, 2024
0d347be
Merge pull request #168 from AlgoLeadMe/40-pknujsp
MunbinLee May 3, 2024
c124bfa
Merge pull request #169 from AlgoLeadMe/41-pknujsp
MunbinLee May 3, 2024
59c99a3
Merge branch 'main' into 49-tgyuuAn
tgyuuAn May 3, 2024
229f372
Merge pull request #174 from AlgoLeadMe/49-tgyuuAn
tgyuuAn May 3, 2024
26f1b3a
Merge branch 'main' into 50-tgyuuAn
tgyuuAn May 3, 2024
3f65705
Merge pull request #175 from AlgoLeadMe/50-tgyuuAn
tgyuuAn May 3, 2024
7e4903e
Merge branch 'main' into 51-tgyuuAn
tgyuuAn May 3, 2024
bc1f839
Merge branch 'main' into 9-H0ngJu
MunbinLee May 3, 2024
7c8ec30
Merge pull request #179 from AlgoLeadMe/51-tgyuuAn
tgyuuAn May 3, 2024
55dc5e8
Merge pull request #172 from AlgoLeadMe/9-H0ngJu
MunbinLee May 3, 2024
4303799
Merge pull request #173 from AlgoLeadMe/42-pknujsp
MunbinLee May 3, 2024
b59cef7
Merge pull request #176 from AlgoLeadMe/43-pknujsp
MunbinLee May 3, 2024
f6c3983
Merge branch 'main' into 10-H0ngJu
MunbinLee May 3, 2024
ed75d21
Merge pull request #177 from AlgoLeadMe/10-H0ngJu
MunbinLee May 3, 2024
8808492
Merge branch 'main' into 11-H0ngJu
MunbinLee May 3, 2024
3fe0703
Merge pull request #178 from AlgoLeadMe/11-H0ngJu
MunbinLee May 3, 2024
5a653be
Merge branch 'main' into 12-H0ngJu
H0ngJu May 6, 2024
c50ebb1
Merge pull request #180 from AlgoLeadMe/12-H0ngJu
H0ngJu May 6, 2024
c12d538
2024-05-06
H0ngJu May 6, 2024
7a2b4fe
2024-05-06
H0ngJu May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions H0ngJu/BFS/์ˆจ๋ฐ”๊ผญ์งˆ4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys
from collections import deque

def input(): return sys.stdin.readline()

N, K = map(int, input().split())

visited = [0] * 100001
time = 0
parent = [-1] * 100001

q = deque([N])
visited[N] = 1

while q:
size = len(q)
for _ in range(size):
location = q.popleft()
if location == K:
print(time)
answer = []
while location != -1:
answer.append(location)
location = parent[location]
answer.reverse()
print(" ".join(map(str, answer)))
break
for next_location in (location + 1, location - 1, location * 2):
if 0 <= next_location <= 100000 and not visited[next_location]:
q.append(next_location)
visited[next_location] = 1
parent[next_location] = location
time += 1
43 changes: 43 additions & 0 deletions H0ngJu/DFS/ABCDE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys

def input(): return sys.stdin.readline().rstrip()

# ์žฌ๊ท€ํ•จ์ˆ˜ fr_check
def fr_check(friend, stack):
stack.append(friend) # ํ˜„์žฌ ์นœ๊ตฌ๋ฅผ ์Šคํƒ์— ์ถ”๊ฐ€
print(stack)

if len(stack) == 5: # ์นœ๊ตฌ 5๋ช… ๋˜๋ฉด
return stack

for x in friends[friend]:
if x not in stack:
result = fr_check(x, stack.copy()) # ๋ณต์‚ฌํ•ด์•ผ ๋ณ„๋„์˜ stack์ด ๋งŒ๋“ค์–ด์ ธ์„œ ์ „๋‹ฌ ๊ฐ€๋Šฅ
if result is not None:
return result

return None # stack์ด 5๊ฐ€ ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ


N, M = map(int, input().split())
friends = [[] for _ in range(N)] #freind[i]์—๋Š” i์˜ ์นœ๊ตฌ ๋‹ด๊ธฐ
fcheck = 0
stack = []


for _ in range(M):
f0, f1 = map(int, input().split())
friends[f0].append(f1)
friends[f1].append(f0)


for idx in range(N):
stack = []
result = fr_check(idx, stack) #idx๋ถ€ํ„ฐ ์ฒดํฌ ์‹œ์ž‘
if result != None and len(result) == 5:
fcheck = 1
print("1")
break

if fcheck == 0:
print(0)
26 changes: 26 additions & 0 deletions H0ngJu/DP/1,2,3 ๋”ํ•˜๊ธฐ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys

def input(): return sys.stdin.readline().strip()

T = int(input())

answer = []
dp = [0] * (11)

for index in range(T):
data = int(input())

for i in range(1, data + 1):
if i == 1:
dp[i] = 1
elif i == 2:
dp[i] = 2
elif i == 3:
dp[i] = 4
else:
dp[i] = dp[i-1] + dp[i-2] + dp[i-3]

answer.append(dp[data])

for a in answer:
print(a, end=" ")
21 changes: 21 additions & 0 deletions H0ngJu/DP/RGB๊ฑฐ๋ฆฌ 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())
INF = 1000*1000+1

house = [[int(x) for x in input().split()] for _ in range(N)]
cost = INF

for first_house in range(3):
dp = [[INF] * 3 for _ in range(N)]
dp[0][first_house] = house[0][first_house]
for i in range(1, N):
dp[i][0] = min(dp[i-1][1], dp[i-1][2]) + house[i][0]
dp[i][1] = min(dp[i-1][0], dp[i-1][2]) + house[i][1]
dp[i][2] = min(dp[i-1][0], dp[i-1][1]) + house[i][2]
dp[N-1][first_house] = INF
cost = min(cost, min(dp[N-1]))

print(cost)
28 changes: 28 additions & 0 deletions H0ngJu/DP/์‰ฌ์šด ๊ณ„๋‹จ ์ˆ˜.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys

DIV = 1_000_000_000

N = int(sys.stdin.readline().rstrip())

dp = [[0] * 10 for _ in range(N+1)]
answer = 0

for i in range(1,N+1):
if i == 1:
for k in range(1,10):
dp[i][k] = 1

else:
for num in range(10):
if num == 0:
dp[i][num] = dp[i-1][1]%DIV
elif num == 9:
dp[i][num] = dp[i-1][8]%DIV
else:
dp[i][num] = (dp[i-1][num-1] + dp[i-1][num+1])%DIV

for k in range(10):
answer += dp[N][k]

print(answer%DIV)

21 changes: 17 additions & 4 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
## โœ๏ธ ๊ธฐ๋ก
## โœ๏ธ ๊ธฐ๋ก

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :----: | :--------: | :------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.05 | ํ | [ํ”„๋กœ์„ธ์Šค](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 |
| 2์ฐจ์‹œ | 2024.03.07 | ํ | [๋‹ค๋ฆฌ๋ฅผ ์ง€๋‚˜๋Š” ํŠธ๋Ÿญ](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 |
| 3์ฐจ์‹œ | 2024.03.10 | ํž™ | [N๋ฒˆ์งธ ํฐ ์ˆ˜](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 |
| 4์ฐจ์‹œ | 2024.03.13 | ํž™ | [๋ฌธ์ œ์ง‘](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 |
| 5์ฐจ์‹œ | 2024.03.16 | ๊ตฌํ˜„ | [์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 |
| 6์ฐจ์‹œ | 2024.03.19 | ์Šคํƒ | [์˜คํฐ์ˆ˜](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 |
| 7์ฐจ์‹œ | 2024.03.22 | DP | [1,2,3 ๋”ํ•˜๊ธฐ](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/166 |
| 8์ฐจ์‹œ | 2024.03.16 | DP | [์‰ฌ์šด ๊ณ„๋‹จ ์ˆ˜](https://www.acmicpc.net/problem/10844) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/170 |
| 9์ฐจ์‹œ | 2024.03.22 | DP | [RGB๊ฑฐ๋ฆฌ 2](https://www.acmicpc.net/problem/17404) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/172 |
| 10์ฐจ์‹œ | 2024.04.03 | BFS | [์ˆจ๋ฐ”๊ผญ์งˆ 4](https://www.acmicpc.net/problem/13913) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/177 |
| 11์ฐจ์‹œ | 2024.04.07 | ๊ตฌํ˜„ | [์‚ฌํƒ• ๊ฒŒ์ž„](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/178 |
| 12์ฐจ์‹œ | 2024.04.09 | DFS | [ABCDE](https://www.acmicpc.net/problem/13023) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/180 |
| 13์ฐจ์‹œ | 2024.05.06 | ์™„์ „ํƒ์ƒ‰ | [๋ฆฌ๋ชจ์ปจ](https://www.acmicpc.net/problem/1107) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/181 |

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
|:----:|:---------:|:----:|:-----:|:----:|
| 1์ฐจ์‹œ | 2024.03.04 | BFS | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/169199">๋ฆฌ์ฝ”์ณ‡ ๋กœ๋ด‡</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/1 |
---
44 changes: 44 additions & 0 deletions H0ngJu/๊ตฌํ˜„/์‚ฌํƒ• ๊ฒŒ์ž„.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys

def input(): return sys.stdin.readline().rstrip()

def eat(row, col):
row_cnt = 0
col_cnt = 0
tmp_col = 1
tmp_row = 1
for idx in range(N-1):
# ์—ด์—์„œ ๋จน์„ ๋•Œ
if data[row][idx] == data[row][idx+1]:
tmp_col += 1
col_cnt = max(col_cnt, tmp_col)
else:
tmp_col = 1

# ํ–‰์—์„œ ๋จน์„ ๋•Œ
if data[idx][col] == data[idx+1][col]:
tmp_row += 1
row_cnt = max(row_cnt, tmp_row)
else:
tmp_row = 1

return max(row_cnt, col_cnt)


N = int(input())
data = [[x for x in input()] for _ in range(N)]
directions = [(0,-1), (0,1), (-1,0),(1,0)]
cnt = 0

for i in range(N):
for k in range(N):
for dir in directions:
dx, dy = dir
x = i+dx
y = k+dy
if 0<=x<N and 0<=y<N:
data[i][k], data[x][y] = data[x][y], data[i][k]
cnt = max(cnt, eat(x,y))
data[i][k], data[x][y] = data[x][y], data[i][k] #๋‹ค์‹œ ๋˜๋Œ๋ฆฌ๊ธฐ

print(cnt)
27 changes: 27 additions & 0 deletions H0ngJu/๊ตฌํ˜„/์š”์„ธํ‘ธ์Šค.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys

def input():
return sys.stdin.readline().rstrip()

def solution(k):
location = 0
cnt = 0

while table:
if cnt == k - 1:
answer.append(table.pop(location))
location -= 1 # ์‚ญ์ œํ•œ ๊ฒฝ์šฐ์—๋Š” ์œ„์น˜๋ฅผ ์•ž์œผ๋กœ ์ด๋™
cnt = 0
else:
cnt += 1
if len(table) != 0:
location = (location + 1) % len(table)

return answer

n, k = map(int, input().split())
table = [i + 1 for i in range(n)]
answer = []

solution(k)
print("<" + ", ".join(map(str, answer)) + ">")
25 changes: 25 additions & 0 deletions H0ngJu/์Šคํƒ/์˜คํฐ์ˆ˜.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
from collections import *

def input(): return sys.stdin.readline().strip()
N = int(input())

arr = list(map(int, input().split()))
arr.reverse()
answer = [-1 for _ in range(N)]

id = 0

stack = []
stack.append((id,arr.pop()))

while arr:
id += 1
arr_data = arr.pop()
while stack and stack[-1][1] < arr_data:
index, data = stack.pop()
answer[index] = arr_data
stack.append((id, arr_data))

for i in answer:
print(i, end=" ")
22 changes: 22 additions & 0 deletions H0ngJu/์™„์ „ํƒ์ƒ‰/๋ฆฌ๋ชจ์ปจ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())
M = int(input())
btn = list(map(int, input().rsplit()))

target = abs(N-100)
cnt = target

for i in range(1000001):
check = True
for str_i in str(i):
if int(str_i) in btn:
check = False
break

if check:
cnt = min(cnt, abs(i - N)+len(str(i)))

print(cnt)
20 changes: 20 additions & 0 deletions H0ngJu/ํ/process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from collections import deque

def solution(priorities, location):
answer = 0
queue = deque([(i, k) for k, i in enumerate(priorities)]) # ํŠœํ”Œ ํ ์ƒ์„ฑ
priorities.sort(reverse=True) # ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ

while queue:
cur = queue.popleft() # ๊ฐ€์žฅ ์•ž์˜ ํ”„๋กœ์„ธ์Šค ๊บผ๋‚ด๊ธฐ (queue.pop(0))
if cur[0] == priorities[0]: # ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋œ ์šฐ์„ ์ˆœ์œ„ == ํ˜„์žฌ ์ˆœ์œ„ -> ๊ฐ€์žฅ ๋†’์Œ
answer += 1 # ์ˆ˜ ++
if cur[1] == location: # ์ฐพ๊ณ ์žํ•˜๋Š” process์ธ ๊ฒฝ์šฐ
break
priorities.pop(0)
else:
queue.append(cur) # ๋’ค๋กœ ๋ฏธ๋ฃจ๊ธฐ

return answer

#test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from collections import deque

def solution(bridge_length, weight, truck_weights):
time = 0
onBridge = deque() # ํ˜„์žฌ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ
truckNum = 0 # ํ˜„์žฌ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ ์ˆ˜
sum = 0 # ํ˜„์žฌ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ ๋ฌด๊ฒŒ์˜ ํ•ฉ
truck_weights = deque(truck_weights)

while truck_weights or onBridge:
time += 1

# ํŠธ๋Ÿญ์ด ๋‹ค๋ฆฌ๋ฅผ ์ง€๋‚˜๊ฐ€๋Š” ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
if onBridge and time - onBridge[0][1] >= bridge_length:
sum -= onBridge.popleft()[0]
truckNum -= 1

# ๋‹ค์Œ ํŠธ๋Ÿญ์ด ๋‹ค๋ฆฌ์— ์˜ฌ๋ผ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
# ํŠธ๋Ÿญ์ด ์žˆ๊ณ  ํ•ฉ์ด weight์„ ๋„˜์ง€ ์•Š์œผ๋ฉฐ, ์ˆ˜๊ฐ€ bridge_length๋ฅผ ๋„˜๊ธฐ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ
if len(truck_weights) != 0 and sum + truck_weights[0] <= weight and truckNum + 1 <= bridge_length:
truck = truck_weights.popleft() # pop
onBridge.append((truck, time)) # ๋‹ค๋ฆฌ ์œ„์˜ truck์— tuple ์ถ”๊ฐ€
sum += truck # ๋ฌด๊ฒŒ ์ถ”๊ฐ€
truckNum += 1 # ๊ฑด๋„ˆ๊ณ  ์žˆ๋Š” ํŠธ๋Ÿญ ์ถ”๊ฐ€

return time
19 changes: 19 additions & 0 deletions H0ngJu/ํž™/N๋ฒˆ์งธ ํฐ ์ˆ˜.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import heapq

line = int(sys.stdin.readline().strip())

heap = []
heapq.heapify(heap)

for i in range(line):
data = list(map(int, sys.stdin.readline().strip().split()))
for s in data:
if len(heap) < line:
heapq.heappush(heap, s)
else:
if s > heap[0]:
heapq.heappop(heap)
heapq.heappush(heap, s)

print(heap[0])
Loading