Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssw6750 committed Sep 28, 2022
1 parent c61101e commit c1db0b2
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 9 deletions.
32 changes: 32 additions & 0 deletions 라인/2.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 6 additions & 3 deletions 라인/3.py
Original file line number Diff line number Diff line change
@@ -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방향
Expand All @@ -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])
Expand Down
20 changes: 14 additions & 6 deletions 라인/4.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 못풀었음ㅜㅠ
# 조건에 맞는 이동방식을 일일이 계산하여 bfs로 풀음
dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]


from collections import deque

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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<n1:
queue.append([[yy, xx], c+1])


def solution(wall):
Expand Down
64 changes: 64 additions & 0 deletions 라인/5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import sys
input = sys.stdin.readline
n, T = map(int, input().split())

def gcd(p, q): # 최대공약수 (뉴클리드 호제법)
if q==0:
return p
return gcd(q, p%q)

def get_divisors(x): # 모든 약수 찾기
res = []
for i in range(1, x+1):
if i * i > 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
'''

0 comments on commit c1db0b2

Please sign in to comment.