diff --git "a/YoonYn9915/Graph/2025-06-16-[\353\260\261\354\244\200]-#14226-\354\235\264\353\252\250\355\213\260\354\275\230.py" "b/YoonYn9915/Graph/2025-06-16-[\353\260\261\354\244\200]-#14226-\354\235\264\353\252\250\355\213\260\354\275\230.py" new file mode 100644 index 0000000..0a0b1bc --- /dev/null +++ "b/YoonYn9915/Graph/2025-06-16-[\353\260\261\354\244\200]-#14226-\354\235\264\353\252\250\355\213\260\354\275\230.py" @@ -0,0 +1,34 @@ +from collections import deque +import sys + +S = int(sys.stdin.readline().strip()) + +# visited[screen][clipboard] +visited = [[-1] * (S + 1) for _ in range(S + 1)] + +queue = deque() +queue.append((1, 0)) # 화면: 1, 클립보드: 0 +visited[1][0] = 0 + +while queue: + screen, clipboard = queue.popleft() + + # 목표 이모티콘 수에 도달하면 종료 + if screen == S: + print(visited[screen][clipboard]) + break + + # 1. 복사 (화면 -> 클립보드) + if visited[screen][screen] == -1: + visited[screen][screen] = visited[screen][clipboard] + 1 + queue.append((screen, screen)) + + # 2. 붙여넣기 (클립보드 -> 화면) + if clipboard != 0 and screen + clipboard <= S and visited[screen + clipboard][clipboard] == -1: + visited[screen + clipboard][clipboard] = visited[screen][clipboard] + 1 + queue.append((screen + clipboard, clipboard)) + + # 3. 삭제 (화면 -1) + if screen - 1 >= 0 and visited[screen - 1][clipboard] == -1: + visited[screen - 1][clipboard] = visited[screen][clipboard] + 1 + queue.append((screen - 1, clipboard)) diff --git "a/YoonYn9915/Graph/2025-06-21-[\353\260\261\354\244\200]-#13549-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" "b/YoonYn9915/Graph/2025-06-21-[\353\260\261\354\244\200]-#13549-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" new file mode 100644 index 0000000..faa5197 --- /dev/null +++ "b/YoonYn9915/Graph/2025-06-21-[\353\260\261\354\244\200]-#13549-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" @@ -0,0 +1,50 @@ +import sys +from collections import deque + +inp = sys.stdin.readline + +N, K = map(int, inp().strip().split()) +# 해당 위치로 도달한 최소 시간 저장 +visited = [-1] * (100_000 + 1) +visited[N] = 0 + +# (위치, 시간) 형식 +queue = deque() +queue.append((N, 0)) + +dx = [2, -1, 1] + +min_time = -1 + +while queue: + subin_loc, time = queue.popleft() + + # 수빈이가 동생에게 도달한 시간까지만 bfs탐색하고 그 후에 종료 + if min_time != -1 and min_time + 2 == time: + break + + # 수빈이가 동생에게 도달한 시간체크 + if min_time == -1 and subin_loc == K: + min_time = visited[subin_loc] + + # 수빈의 위치에서 3가지 이동 + for i in range(3): + if i == 0: + new_loc = subin_loc * dx[i] + else: + new_loc = subin_loc + dx[i] + + # 새 위치가 범위 안 + if 0 <= new_loc <= 100_000: + # 새로 방문한 위치가 이전에 와보지 못했다면, + if visited[new_loc] == -1: + # 방문 시간 설정해주고 경로 초기화 + if i == 0: + visited[new_loc] = visited[subin_loc] + queue.append((new_loc, time)) + else: + visited[new_loc] = visited[subin_loc] + 1 + queue.append((new_loc, time + 1)) + + +print(visited[K]) diff --git "a/YoonYn9915/implementation/2025-06-21-[\353\260\261\354\244\200]-#10828-\354\212\244\355\203\235.py" "b/YoonYn9915/implementation/2025-06-21-[\353\260\261\354\244\200]-#10828-\354\212\244\355\203\235.py" new file mode 100644 index 0000000..148c1bc --- /dev/null +++ "b/YoonYn9915/implementation/2025-06-21-[\353\260\261\354\244\200]-#10828-\354\212\244\355\203\235.py" @@ -0,0 +1,30 @@ +import sys +input = sys.stdin.readline + +N = int(input()) + +stack = [] +def query(): + Q = input().split() + if Q[0] == "push": + stack.append(int(Q[1])) + elif Q[0] == "pop": + if len(stack): + print(stack.pop()) + else: + print(-1) + elif Q[0] == "size": + print(len(stack)) + elif Q[0] == "empty": + if len(stack): + print(0) + else: + print(1) + elif Q[0] == "top": + if len(stack): + print(stack[-1]) + else: + print(-1) + +for _ in range(N): + query() \ No newline at end of file