diff --git "a/2023/May/week5/\354\235\264\354\240\225\354\232\261/1956_\354\232\264\353\217\231.py" "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/1956_\354\232\264\353\217\231.py" new file mode 100644 index 0000000..3ffcd76 --- /dev/null +++ "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/1956_\354\232\264\353\217\231.py" @@ -0,0 +1,30 @@ +import sys +sys.setrecursionlimit(10 ** 5) +input = sys.stdin.readline + +v,e = map(int,input().split()) +graph = [[] for _ in range(v+1)] + +for _ in range(e): + a,b,c = map(int,input().split()) + graph[a].append((c,b)) + +dist = [[1e10 for _ in range(v+1)] for _ in range(v+1)] + +for _from in range(1,v+1): + for _d, _to in graph[_from]: + dist[_from][_to] = _d + +for k in range(1,v+1): + for i in range(1,v+1): + for j in range(1,v+1): + dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]) + +res = 1e10 + +for i in range(1,v+1): + res = min(res, dist[i][i]) + +if res == 1e10: + print(-1) +else: print(res) \ No newline at end of file diff --git "a/2023/May/week5/\354\235\264\354\240\225\354\232\261/21314_\353\257\274\352\262\270\354\210\230.py" "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/21314_\353\257\274\352\262\270\354\210\230.py" new file mode 100644 index 0000000..38cc478 --- /dev/null +++ "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/21314_\353\257\274\352\262\270\354\210\230.py" @@ -0,0 +1,50 @@ +import sys +import re +sys.setrecursionlimit(10 ** 5) +input = sys.stdin.readline + +_s = input().rstrip() + +def get_MK_num(s): + return "5" + "0" * (len(s)-1) + +def applyMK(s): + regex = "[M]+K" + _list = re.compile(regex).findall(s) + sub = list(re.sub(regex,"*",s)) + idx = 0 + + for i in range(len(sub)): + if sub[i] == "*": + sub[i] = get_MK_num(_list[idx]) + idx += 1 + return sub + +def get_MM_num(s): + return "1" + "0" * (len(s)-1) + +def applyMM(s): + regex = "M[M]+" + _list = re.compile(regex).findall(s) + sub = list(re.sub(regex,"*",s)) + idx = 0 + + for i in range(len(sub)): + if sub[i] == "*": + sub[i] = get_MM_num(_list[idx]) + idx += 1 + return sub + +def go(l): + for i in range(len(l)): + if l[i] == "M": + l[i] = "1" + if l[i] == "K": + l[i] = "5" + return "".join(l) + +big = applyMK(_s) +small = applyMM(_s) + +print(go(big)) +print(go(small)) \ No newline at end of file diff --git "a/2023/May/week5/\354\235\264\354\240\225\354\232\261/2206_\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.py" "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/2206_\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.py" new file mode 100644 index 0000000..aef9a81 --- /dev/null +++ "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/2206_\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.py" @@ -0,0 +1,37 @@ +import sys +from collections import deque +sys.setrecursionlimit(10 ** 5) +input = sys.stdin.readline + +n,m = map(int,input().split()) +arr = [list(map(int,input().rstrip())) for _ in range(n)] +dx = [-1,1,0,0] +dy = [0,0,-1,1] +visited = [[[1e10,1e10] for _ in range(m)] for _ in range(n)] + +q = deque() +q.append((0,0,1)) +visited[0][0][1] = 1 + +while q: + x,y,can = q.popleft() + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + if nx < 0 or ny < 0 or nx >= n or ny >= m: continue + if visited[nx][ny][can] != 1e10: continue + if arr[nx][ny] == 1: + if can: + visited[nx][ny][0] = visited[x][y][1] + 1 + q.append((nx,ny,0)) + else: + visited[nx][ny][can] = visited[x][y][can] + 1 + q.append((nx,ny,can)) + +# for e in visited: +# print(e) + +if min(visited[n-1][m-1]) == 1e10: + print(-1) +else: + print(min(visited[n-1][m-1])) \ No newline at end of file diff --git "a/2023/May/week5/\354\235\264\354\240\225\354\232\261/22942_\353\215\260\354\235\264\355\204\260\354\262\264\354\273\244.py" "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/22942_\353\215\260\354\235\264\355\204\260\354\262\264\354\273\244.py" new file mode 100644 index 0000000..7580771 --- /dev/null +++ "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/22942_\353\215\260\354\235\264\355\204\260\354\262\264\354\273\244.py" @@ -0,0 +1,24 @@ +# 답 봤습니다...... +import sys +sys.setrecursionlimit(10 ** 5) +input = sys.stdin.readline + +n = int(input()) +circles = [] + +for i in range(n): + x,r = map(int,input().split()) + circles.append((x-r,i)) + circles.append((x+r,i)) +circles.sort() + +st = [] + +for x,i in circles: + if st and st[-1] == i: + st.pop() + else: + st.append(i) + +if not st: print("YES") +else: print("NO") \ No newline at end of file diff --git "a/2023/May/week5/\354\235\264\354\240\225\354\232\261/2615_\354\230\244\353\252\251.py" "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/2615_\354\230\244\353\252\251.py" new file mode 100644 index 0000000..3b3cdfa --- /dev/null +++ "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/2615_\354\230\244\353\252\251.py" @@ -0,0 +1,42 @@ +import sys +sys.setrecursionlimit(10 ** 5) +input = sys.stdin.readline + +arr = [list(map(int,input().split())) for _ in range(19)] +dx = [-1,1,0,0,-1,-1,1,1] +dy = [0,0,-1,1,-1,1,-1,1] +reverse = [1,0,3,2,7,6,5,4] + +def go(x,y,l,d): + nx = x + dx[d] + ny = y + dy[d] + if nx < 0 or ny < 0 or nx >= 19 or ny >= 19: + return l + + if arr[nx][ny] != arr[l[0][1]][l[0][0]]: + return l + l.append((ny,nx)) + return go(nx,ny,l,d) + +# one = go(2,1,[(2,1)],7) +# two= go(2,1,[(2,1)],reverse[7]) +# res = one + two +# res.sort() + +# print(res) + +for i in range(19): + for j in range(19): + for k in range(8): + if arr[i][j] == 0: continue + one = go(i,j,[(j,i)],k) + two = go(i,j,[(j,i)],reverse[k]) + res = one + two + if len(res) == 6: + res.sort() + # print(res) + print(arr[res[0][1]][res[0][0]]) + print(f"{res[0][1]+1} {res[0][0]+1}") + exit() + +print(0) \ No newline at end of file diff --git "a/2023/May/week5/\354\235\264\354\240\225\354\232\261/4256_\355\212\270\353\246\254.py" "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/4256_\355\212\270\353\246\254.py" new file mode 100644 index 0000000..bca13c9 --- /dev/null +++ "b/2023/May/week5/\354\235\264\354\240\225\354\232\261/4256_\355\212\270\353\246\254.py" @@ -0,0 +1,28 @@ +import sys +sys.setrecursionlimit(10 ** 5) +input = sys.stdin.readline + +t = int(input()) +for _ in range(t): + n = int(input()) + tree = {} + preorder = list(map(int,input().split())) + inorder = list(map(int,input().split())) + + def make_tree(here,_pre,_in): + if not _pre or not _in: return + tree[here] = _pre[0] + idx = _in.index(_pre[0]) + make_tree(here*2,_pre[1:1+idx],_in[:idx]) + make_tree(here*2+1,_pre[1+idx:],_in[idx+1:]) + return + make_tree(1,preorder,inorder) + res = [] + def postorder(here): + if here*2 in tree: + postorder(here*2) + if here*2+1 in tree: + postorder(here*2+1) + res.append(tree[here]) + postorder(1) + print(" ".join(map(str,res))) \ No newline at end of file