-
Notifications
You must be signed in to change notification settings - Fork 5
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
16-janghw0126 #183
Open
janghw0126
wants to merge
11
commits into
main
Choose a base branch
from
16-janghw0126
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
16-janghw0126 #183
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5fa0966
2024-09-09 μ€ μΈμ°κΈ°
janghw0126 e244b99
2024-09-17 μ΄μ€ μ°μ μμ ν
janghw0126 e6d1a40
2024-09-24 IOIOI
janghw0126 0188acb
2024-09-27 ν λ§ν
janghw0126 87b24ce
2024-10-05 μ λ‘μμ½
janghw0126 b34a1f1
2024-10-05 μ λ‘μλ§Ή
janghw0126 4bd6437
Merge branch 'main' into 14-janghw0126
janghw0126 d3ead71
Update README.md
janghw0126 46f9909
2024-10-12 μ§κ²λ€λ¦¬
janghw0126 32e6ff7
2024-10-30 λ¬Έμμ΄ νλ°
janghw0126 6d5d6b6
2024-10-30 λ¬Έμμ΄ νλ°
janghw0126 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import sys | ||
from collections import deque | ||
|
||
input = sys.stdin.readline | ||
|
||
def bfs(x, y, graph, visited): | ||
q = deque() | ||
q.append((x, y)) | ||
visited[x][y] = True | ||
|
||
# μνμ’μ° λ°©ν₯ μ μΈνκΈ° | ||
dx, dy = [1, -1, 0, 0], [0, 0, 1, -1] | ||
|
||
while q: | ||
x, y = q.popleft() | ||
|
||
for i in range(4): | ||
nx, ny = x + dx[i], y + dy[i] | ||
|
||
if 0 <= nx < n and 0 <= ny < n and not visited[nx][ny]: | ||
# μμμ΄ κ°κ³ λ°©λ¬Ένμ§ μμ κ²½μ°μλ§ νμ λ£μ | ||
if graph[x][y] == graph[nx][ny]: | ||
visited[nx][ny] = True | ||
q.append((nx, ny)) | ||
|
||
n = int(input()) | ||
graph = [list(input().strip()) for _ in range(n)] | ||
|
||
# 첫 λ²μ§Έ λ°©λ¬Έ λ°°μ΄μ μ μμΈ (R, G, B ꡬλΆν¨) | ||
visited = [[False] * n for _ in range(n)] | ||
normal_count = 0 | ||
|
||
# λ λ²μ§Έ λ°©λ¬Έ λ°°μ΄μ μ λ‘μλ§ΉμΈ (R, G κ΅¬λΆ μ ν¨) | ||
visited_rg = [[False] * n for _ in range(n)] | ||
rg_count = 0 | ||
|
||
# μ μμΈ κ·Έλ£Ή κ°μ ꡬνκΈ° | ||
for i in range(n): | ||
for j in range(n): | ||
if not visited[i][j]: | ||
bfs(i, j, graph, visited) | ||
normal_count += 1 | ||
|
||
# μ λ‘μλ§ΉμΈ κ²½μ° 'G'λ₯Ό 'R'λ‘ λ°κΎΈκΈ° | ||
for i in range(n): | ||
for j in range(n): | ||
if graph[i][j] == 'G': | ||
graph[i][j] = 'R' | ||
|
||
# μ λ‘μλ§ΉμΈ κ·Έλ£Ή κ°μ ꡬνκΈ° | ||
for i in range(n): | ||
for j in range(n): | ||
if not visited_rg[i][j]: | ||
bfs(i, j, graph, visited_rg) | ||
rg_count += 1 | ||
|
||
print(normal_count, rg_count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from collections import deque | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
# ν μ€νΈ μΌμ΄μ€λ₯Ό μ λ ₯λ°μ | ||
m, n = map(int, input().split()) | ||
tomato_grid = [list(map(int, input().split())) for _ in range(n)] | ||
|
||
# μ΅μ ν λ§ν μ’νλ₯Ό νμ μΆκ°ν¨ | ||
queue = deque([(i, j) for i in range(n) for j in range(m) if tomato_grid[i][j] == 1]) | ||
|
||
# λ°©ν₯ 벑ν°λ₯Ό μ΄κΈ°νν¨ (μ, ν, μ’, μ°) | ||
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] | ||
|
||
# BFS νμμ μμν¨ | ||
def bfs(): | ||
while queue: | ||
x, y = queue.popleft() | ||
for dx, dy in directions: | ||
nx, ny = x + dx, y + dy | ||
# λ²μ λ΄μ μκ³ , μ΅μ§ μμ ν λ§ν (0)μΌ κ²½μ° μ΅ν | ||
if 0 <= nx < n and 0 <= ny < m and tomato_grid[nx][ny] == 0: | ||
tomato_grid[nx][ny] = tomato_grid[x][y] + 1 | ||
queue.append((nx, ny)) | ||
|
||
# BFSλ₯Ό μ€νν¨ | ||
bfs() | ||
|
||
# κ²°κ³Όλ₯Ό κ³μ°ν¨ | ||
days = 0 | ||
for row in tomato_grid: | ||
# μ΅μ§ μμ ν λ§ν κ° μμΌλ©΄ -1μ μΆλ ₯ν¨ | ||
if 0 in row: | ||
print(-1) | ||
exit() | ||
# κ°μ₯ ν° κ°μ΄ κ±Έλ¦° λ μ§λ₯Ό κ³μ°ν¨ | ||
days = max(days, max(row)) | ||
|
||
# μμμ 1μμ νμΌλ―λ‘ κ²°κ³Όμμ 1μ λΉΌμ€ | ||
print(days - 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import sys | ||
input=sys.stdin.readline | ||
|
||
# λ¬Έμμ΄ μ λ ₯νκΈ° | ||
string = input().strip() | ||
# νλ° λ¬Έμμ΄ μ λ ₯νκΈ° | ||
bomb_string = input().strip() | ||
|
||
# νλ° λ¬Έμμ΄ κΈΈμ΄ κ³μ°νκΈ° | ||
bomb_len=len(bomb_string) | ||
|
||
# κ²°κ³Ό μΆλ ₯ 리μ€νΈ μ μΈ | ||
stack=[] | ||
|
||
# stackμ μμλκ³ , νλ°λ¬Έμμ΄μ΄ μλ κ²½μ° pop | ||
for str in string: | ||
stack.append(str) | ||
# νλ° λ¬Έμμ΄κ³Ό stack λ·λΆλΆμ΄ κ°μ κ²½μ° | ||
if ''.join(stack[-bomb_len:])==bomb_string: | ||
# ν΄λΉ λ¬Έμμ΄ pop | ||
for _ in range(bomb_len): | ||
stack.pop() | ||
|
||
# κ²°κ³Ό μΆλ ₯ | ||
print(''.join(stack) if stack else "FRULA",end='') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sys | ||
from collections import deque | ||
|
||
n, m = map(int, sys.stdin.readline().split()) | ||
|
||
# κ·Έλνμ μ§μ μ°¨μ 리μ€νΈλ₯Ό μ΄κΈ°νν¨ | ||
graph = [[] for _ in range(n + 1)] | ||
deg = [0] * (n + 1) | ||
q = deque() | ||
res = [] | ||
|
||
# λΉκ΅ κ΄κ³ μ λ ₯κ³Ό κ·Έλνλ₯Ό ꡬμ±ν¨ | ||
for _ in range(m): | ||
u, v = map(int, sys.stdin.readline().rstrip().split()) | ||
# uκ° v μμ μμΌ ν¨ | ||
graph[u].append(v) | ||
# vμ μ§μ μ°¨μλ₯Ό μ¦κ°μν΄ | ||
deg[v] += 1 | ||
|
||
# μ§μ μ°¨μκ° 0μΈ λ Έλ νμ μ½μ ν¨ | ||
for i in range(1, n + 1): | ||
if deg[i] == 0: | ||
q.append(i) | ||
|
||
# μμ μ λ ¬μ μμν¨ | ||
while q: | ||
# μ§μ μ°¨μκ° 0μΈ λ Έλλ₯Ό νμμ κΊΌλ | ||
cur = q.popleft() | ||
# κ²°κ³Ό 리μ€νΈμ μΆκ°ν¨ | ||
res.append(cur) | ||
|
||
# νμ¬ λ Έλ λ€μ μμΌ νλ λ Έλλ€μ μ§μ μ°¨μλ₯Ό κ°μμν΄ | ||
for next_node in graph[cur]: | ||
deg[next_node] -= 1 | ||
# μ§μ μ°¨μκ° 0μ΄ λλ©΄ νμ μΆκ°ν¨ | ||
if deg[next_node] == 0: | ||
q.append(next_node) | ||
|
||
print(*res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
def solution(distance, rocks, n): | ||
rocks.sort() | ||
rocks.append(distance) | ||
left, right = 1, distance | ||
|
||
while left <= right: | ||
mid = (left+right) // 2 | ||
current = 0 | ||
removed_rocks = 0 | ||
|
||
for rock in rocks: | ||
if rock-current < mid: | ||
removed_rocks += 1 | ||
else: | ||
current = rock | ||
|
||
if removed_rocks > n: | ||
right = mid-1 | ||
else: | ||
answer = mid | ||
left = mid+1 | ||
|
||
return answer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
n = int(input()) | ||
m = int(input()) | ||
sequence = input().rstrip() | ||
|
||
# ν¬ ν¬μΈν° μκ³ λ¦¬μ¦μ μν΄μ μ’μ° ν¬μΈν° μ μΈ | ||
start, current = 0, 0 | ||
# 'IOI' ν¨ν΄μ μ°Ύμ νμ μ μΈ | ||
pattern_count = 0 | ||
|
||
# λ¬Έμμ΄ λ²μ λ΄μμ λ°λ³΅ | ||
while current < m: | ||
# νμ¬ μμΉμμ 'IOI' ν¨ν΄μ΄ λ°κ²¬λ κ²½μ° | ||
if sequence[current:current + 3] == 'IOI': | ||
# ν¨ν΄μ μ°ΎμΌλ©΄ ν¬μΈν°λ₯Ό λ μΉΈμ© μ΄λ | ||
current += 2 | ||
# ν¨ν΄μ κΈΈμ΄κ° 'N'μ λ§λ κ²½μ° | ||
if current - start == 2 * n: | ||
# ν¨ν΄ μΉ΄μ΄νΈ μ¦κ° | ||
pattern_count += 1 | ||
# ν¨ν΄μ μμ±νμΌλ μμ ν¬μΈν°λ λ μΉΈ μ΄λ | ||
start += 2 | ||
else: | ||
# ν¨ν΄μ΄ λ§μ§ μμΌλ©΄ ν μΉΈμ© μ΄λ | ||
current += 1 | ||
# μμ ν¬μΈν°λ₯Ό νμ¬ ν¬μΈν° μμΉλ‘ μ¬μ€μ | ||
start = current | ||
|
||
# ν¨ν΄ νμ μΆλ ₯ | ||
print(pattern_count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import sys | ||
import heapq | ||
|
||
def solve(): | ||
input = sys.stdin.readline | ||
T = int(input()) | ||
|
||
for _ in range(T): | ||
min_heap = [] # μ΅μ ν | ||
max_heap = [] # μ΅λ ν (μμλ‘ λ³ννμ¬ μ μ₯) | ||
count = int(input()) # λͺ λ Ήμ΄ μ | ||
status = [1] * count # μμ μν μΆμ (1: μ ν¨, 0: μμ λ¨) | ||
|
||
for i in range(count): | ||
command, value = input().split() | ||
value = int(value) | ||
|
||
if command == "I": # μ½μ μ°μ° | ||
heapq.heappush(min_heap, (value, i)) | ||
heapq.heappush(max_heap, (-value, i)) | ||
elif command == "D": # μμ μ°μ° | ||
if value == -1: # μ΅μκ° μμ | ||
if min_heap: | ||
status[heapq.heappop(min_heap)[1]] = 0 | ||
elif value == 1: # μ΅λκ° μμ | ||
if max_heap: | ||
status[heapq.heappop(max_heap)[1]] = 0 | ||
|
||
# μ ν¨νμ§ μμ κ° μ κ±° | ||
while min_heap and status[min_heap[0][1]] == 0: | ||
heapq.heappop(min_heap) | ||
while max_heap and status[max_heap[0][1]] == 0: | ||
heapq.heappop(max_heap) | ||
|
||
# κ²°κ³Ό μΆλ ₯ | ||
if not min_heap or not max_heap: | ||
print("EMPTY") | ||
else: | ||
print(-max_heap[0][0], min_heap[0][0]) | ||
|
||
if __name__ == "__main__": | ||
solve() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
''.join()μ μ¬μ©νμ¬ λ¬Έμμ΄μ λΉκ΅νλ λΆλΆμ μ΅μ ννμ¬ μκ°μ μ‘°κΈ λ μ€μ¬λ³΄μμ΅λλ€ !
μλ μ½λλ³΄λ€ μ‘°κΈ λ μκ°μ΄ λΉ¨λΌμ§ κ²μ νμΈν μ μμμ΅λλ€ !