diff --git "a/\353\235\274\354\235\270/2.py" "b/\353\235\274\354\235\270/2.py" new file mode 100644 index 0000000..015e853 --- /dev/null +++ "b/\353\235\274\354\235\270/2.py" @@ -0,0 +1,32 @@ +import sys +input = sys.stdin.readline + +K , n_slang = map(int, input().split()) +slangs = [input().strip() for _ in range(n_slang)] +chat = input().strip() + +def match(slang, word): + n = len(slang) + m = len(word) + dy = [[False for _ in range(m+1)] for _ in range(n+1)] + dy[0][0] = True + + for i in range(1, n+1): + for j in range(1, m+1): + if slang[i-1] == word[j-1]: + dy[i][j] |= dy[i-1][j-1] + if word[j-1] == '.': + for k in range(1, K+1): + if i - k >= 0: + dy[i][j] |= dy[i-k][j-1] + + return dy[n][m] + +ans = [] +for word in chat.split(): + if any(match(slang, word) for slang in slangs): + ans.append('#' * len(word)) + else: + ans.append(word) + +print(*ans) diff --git "a/\353\235\274\354\235\270/3.py" "b/\353\235\274\354\235\270/3.py" index d1df05c..e3d03f1 100644 --- "a/\353\235\274\354\235\270/3.py" +++ "b/\353\235\274\354\235\270/3.py" @@ -1,7 +1,10 @@ +# 시간이 10억분 주어지지만 방문하는 격자는 최대 30*30 + + from collections import deque # n=3; m=2; fires=[[1,1]]; ices=[[3,3]] -n=5; m=3; fires=[[5,5], [1,3], [5,2]]; ices=[[1,5],[3,2]] +n=5; m=1000000000; fires=[[5,5], [1,3], [5,2]]; ices=[[1,5],[3,2]] dx = [0, 0, -1, 1, 1, 1, -1, -1] # (0~3) 상하좌우 (4~7) 대각 4방향 @@ -10,11 +13,11 @@ def fire(y, x, mt, t, nn): # 좌표, 주어진 배열, 시간, nn = 가로길이 = 세로길이 visited = [] queue = deque([[[y, x], t+1]]) - mt[y][x] -=1 # + mt[y][x] -=1 # 정가운데 0분일때 고려 x while queue: n = queue.popleft() - if n[0] not in visited and n[1] > 0: + if n[0] not in visited and n[1] > 0: # 방문하지 않고 시간이 0분 이상 남았을때 y1 = n[0][0] x1 = n[0][1] visited.append(n[0]) diff --git "a/\353\235\274\354\235\270/4.py" "b/\353\235\274\354\235\270/4.py" index 55bdd7b..8a8a90b 100644 --- "a/\353\235\274\354\235\270/4.py" +++ "b/\353\235\274\354\235\270/4.py" @@ -1,5 +1,7 @@ -# 못풀었음ㅜㅠ # 조건에 맞는 이동방식을 일일이 계산하여 bfs로 풀음 +dy = [0, 0, 1, -1] +dx = [1, -1, 0, 0] + from collections import deque @@ -25,7 +27,6 @@ def BFS(y, x, wall, n1, m, visited): if visited[y1][x1] > c: visited[y1][x1] = c - # case1 오른쪽 2칸 if y1-1 >= 0 and x1+2 < n1: f = True @@ -43,10 +44,10 @@ def BFS(y, x, wall, n1, m, visited): if y1-1 >= 0 and x1-2 >= 0: f = True for i in range(3): - if wall[y-1][x-i] != '.': + if wall[y1-1][x1-i] != '.': f = False break - if wall[y][x-1] != '.': + if wall[y1][x1-1] != '.': f = False break if f == True: @@ -69,10 +70,10 @@ def BFS(y, x, wall, n1, m, visited): if y1-1 >= 0 and x1-3 >= 0: f = True for i in range(4): - if wall[y-1][x-i] != '.': + if wall[y1-1][x1-i] != '.': f = False break - if wall[y][x-1] != '.' or wall[y][x-2] != '.': + if wall[y1][x1-1] != '.' or wall[y1][x1-2] != '.': f = False break if f == True: @@ -92,6 +93,13 @@ def BFS(y, x, wall, n1, m, visited): if y1-1 >= 0 and x1-1>=0: if wall[y1-1][x1] == '.' and wall[y1][x1-1] == '.': queue.append([[y1-1, x1-1],c+1]) + + # 상하좌우 + for i in range(4): + yy = y1+dy[i] + xx = x1+dx[i] + if 0<= yy < m and 0<=xx x: break + if x % i == 0: + res.append(i) + res.append(x // i) + + return res + +def solve(A, B, M): + # (A, B) -> M일 연체료 + K = M // A + return B * (K+1) + +q = [list(map(int, input().split())) for _ in range(n)] +q.sort(key = lambda x: x[0]) + +money_gcd = 0 +for i in range(n): + money_gcd = gcd(money_gcd, q[i][1]) + +candidates = get_divisors(money_gcd) +min_ans, max_ans = sys.maxsize, 0 +for cand_money in candidates: + L, R = 1, 1000000 + for time, cost in q: + K = cost//cand_money -1 + # upper + if K > 0: + R = min(R, time//K) + + # lower + L = max(L, time//(K+1)) + + # L < A <= R + if L >= R: + continue + + max_ans = max(max_ans, solve(L+1, cand_money, T)) + min_ans = min(min_ans, solve(R, cand_money, T)) + +if max_ans == 0: + print(-1) +else: + print(min_ans, max_ans) + +''' +5 27 +4 1000 +6 1000 +21 3000 +16 2000 +26 3000 +''' \ No newline at end of file