Skip to content

Commit 6d96068

Browse files
authored
Merge pull request #124 from learntosurf/main
Learntosurf / 1월 3주차 / 6문제
2 parents 4e18114 + 550fa31 commit 6d96068

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
T = int(input()) # 테스트케이스의 개수
5+
6+
for _ in range(T):
7+
# 수첩1
8+
N = int(input())
9+
note1 = set(map(int, input().split()))
10+
# 수첩2
11+
M = int(input())
12+
note2 = list(map(int, input().split()))
13+
14+
for num in note2:
15+
if num in note1:
16+
print(1)
17+
else:
18+
print(0)
19+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
K, N = map(int, input().split())
5+
lan = [int(input()) for _ in range(K)]
6+
7+
# 탐색 대상: 랜선의 길이
8+
start = 1
9+
end = max(lan)
10+
11+
while start <= end:
12+
mid = (start + end) // 2
13+
lines = 0 # 랜선의 개수
14+
for i in lan:
15+
lines += i // mid
16+
if lines >= N: # 랜선의 개수가 많음 (랜선의 길이가 짧음)
17+
start = mid + 1
18+
else: # 랜선의 개수가 적음 (랜선의 길이가 김)
19+
end = mid - 1
20+
21+
print(end)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
input = sys.stdin.readline
3+
from bisect import bisect_left, bisect_right
4+
5+
N, M = map(int, input().split())
6+
points = list(map(int, input().split()))
7+
lines = [tuple(map(int, input().split())) for _ in range(M)]
8+
9+
points.sort()
10+
11+
counts = []
12+
for start, end in lines:
13+
left = bisect_left(points, start)
14+
right = bisect_right(points, end)
15+
counts.append(right - left)
16+
17+
print("\n".join(map(str, counts)))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N, M = map(int, input().split()) # 강의의 수, 블루레이의 수
5+
time = list(map(int, input().split())) # 강의의 길이
6+
7+
# time.sort() # 강의의 순서가 바뀌면 안됨
8+
9+
# 탐색 대상: 블루레이의 크기
10+
start = max(time)
11+
end = sum(time)
12+
13+
while start <= end:
14+
mid = (start + end) // 2
15+
16+
total = 0 # 현재 블루레이에 담은 강의 길이
17+
count = 1 # 블루레이 개수
18+
for t in time:
19+
if total + t > mid: # 블루레이의 크기를 초과하는 경우
20+
count += 1 # 블루레이 개수 증가
21+
total = 0 # 블루레이에 담은 강의 길이 초기화
22+
total += t # 블루레이에 강의 추가
23+
24+
# 블루레이 개수를 확인하고 이진탐색 범위 조정
25+
if count <= M:
26+
answer = mid # 가능한 블루레이 크기 저장
27+
end = mid - 1
28+
else:
29+
start = mid + 1
30+
31+
print(answer)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
S1 = list(input().strip())
5+
S2 = list(input().strip())
6+
n, m = len(S1), len(S2)
7+
8+
dp = [[0] * (m+1) for _ in range(n+1)]
9+
10+
max_len = 0
11+
12+
for i in range(1, n+1):
13+
for j in range(1, m+1):
14+
# 문자열 S1과 S2의 현재 위치의 문자를 비교
15+
if S1[i-1] == S2[j-1]:
16+
dp[i][j] = dp[i-1][j-1] + 1 # 이전 공통 부분 문자열에 현재 문자를 추가하여 길이를 연장
17+
max_len = max(max_len, dp[i][j])
18+
else:
19+
dp[i][j] = 0 # 다르면 공통 부분 문자열이 끊어짐
20+
21+
print(max_len)

0 commit comments

Comments
 (0)