1931_회의실 배정 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import sys N = int(sys.stdin.readline().rstrip()) arr = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] schedule = sorted(arr, key=lambda x: (x[1], x[0])) count, end = 0, 0 for s, f in schedule: if s >= end: count += 1 end = f print(count) # 왠지 정렬을 잘하면 계산이 쉬울 것 같아서.
D4_1226_미로1 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 31 32 33 34 35 36 37 38 39 40 41 42 dx = [0,1, 0, -1] dy = [1,0, -1, 0 ] def IsSafe(x, y): if 0<= x < 16 and 0 <= y < 16: return True def DFS(x, y): global result visited[x][y] = 1 if arr[x][y] == 3: result = 1 for i in range(4): nx = x + dx[i] ny = y + dy[i] if IsSafe(nx, ny) and visited[nx][ny] == 0 and arr[nx][ny] !
D4_1218_괄호 짝짓기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 def Pair_bracket(): for i in range(L): if q[i] in check: ni = i - 1 while True: if q[ni] == 0: ni -= 1 else: break a = q[ni] b = check[q[i]] if a == b: q[i] = 0 q[ni] = 0 else: return 0 return 1 check = {")" :"(", "]":"[", "}":"{", ">":"<"} for T in range(10): L = int(input()) q = list(input()) print(f'#{T+1}{Pair_bracket()}')
1918_후위 표기식 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 import sys from collections import deque text = sys.stdin.readline().rstrip() # 후위 표기법 알고리즘 operator = {"+":1, "-":1, "*":2 , "/":2, "(":0, ")":0} stack = deque() result = "" for i in text: if i not in operator: result += i elif i == "(": stack.