-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
''' |