Skip to content

Commit

Permalink
Merge pull request #113 from tommy16102/junguk
Browse files Browse the repository at this point in the history
5월 5주차 junguk
  • Loading branch information
ParangBird authored Jun 10, 2023
2 parents ad4bbb3 + 227f981 commit c1f2193
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 2023/May/week5/이정욱/1956_운동.py
Original file line number Diff line number Diff line change
@@ -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)
50 changes: 50 additions & 0 deletions 2023/May/week5/이정욱/21314_민겸수.py
Original file line number Diff line number Diff line change
@@ -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))
37 changes: 37 additions & 0 deletions 2023/May/week5/이정욱/2206_벽부수고이동하기.py
Original file line number Diff line number Diff line change
@@ -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]))
24 changes: 24 additions & 0 deletions 2023/May/week5/이정욱/22942_데이터체커.py
Original file line number Diff line number Diff line change
@@ -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")
42 changes: 42 additions & 0 deletions 2023/May/week5/이정욱/2615_오목.py
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 28 additions & 0 deletions 2023/May/week5/이정욱/4256_트리.py
Original file line number Diff line number Diff line change
@@ -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)))

0 comments on commit c1f2193

Please sign in to comment.