Skip to content

Commit 0f331cd

Browse files
Merge pull request #745 from gmlrude/main
[박희경] 123차 라이브 코테 제출
2 parents 9f1665e + 3e42809 commit 0f331cd

3 files changed

Lines changed: 88 additions & 14 deletions

File tree

live12/test122/문제2/박희경.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22

33
input = sys.stdin.readline
44

5-
n = int(input())
5+
n, m = map(int, input().split())
6+
area = []
7+
for _ in range(n):
8+
area.append(list(map(int, input().split())))
9+
10+
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
11+
for i in range(1, n + 1):
12+
for j in range(1, m + 1):
13+
prefix_sum[i][j] = prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1] + area[i-1][j-1]
14+
615
k = int(input())
7-
sensor = list(map(int, input().split()))
8-
sensor.sort()
16+
for _ in range(k):
17+
x1, y1, x2, y2 = map(int, input().split())
18+
result = prefix_sum[x2][y2] - prefix_sum[x1 - 1][y2] - prefix_sum[x2][y1 - 1] + prefix_sum[x1-1][y1-1]
19+
print(result)
920

10-
res, cnt = 0, 1
11-
for i in range(n):
12-
if i % 2 != 0:
13-
if i == n - 1: abs(sensor[i] - sensor[i-1])
14-
else:
15-
res += min(abs(sensor[i] - sensor[i-1]), abs(sensor[i+1] - sensor[i]))
16-
else:
17-
if cnt < k:
18-
cnt += 1
19-
20-
print(res)
21+
"""
22+
4 4
23+
9 14 29 7
24+
1 31 6 13
25+
21 26 40 16
26+
8 38 11 23
27+
3
28+
1 1 3 2
29+
1 1 1 4
30+
1 1 4 4
31+
"""
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
g = int(input())
6+
p = int(input())
7+
8+
gate = [i for i in range(g + 1)]
9+
10+
# gi 이하에서 가장 가까운 사용 가능한 지점 찾기
11+
def find(x):
12+
if gate[x] != x: # 이미 다른 비행기가 도킹한 경우
13+
gate[x] = find(gate[x])
14+
return gate[x]
15+
16+
def union(x, y):
17+
x = find(x)
18+
y = find(y)
19+
gate[x] = y
20+
21+
cnt = 0
22+
for _ in range(p):
23+
gi = int(input())
24+
first = find(gi)
25+
if first == 0: # 도킹 불가
26+
break
27+
union(first, first-1)
28+
cnt += 1
29+
30+
print(cnt)
31+
32+
33+
"""
34+
4
35+
6
36+
2
37+
2
38+
3
39+
3
40+
4
41+
4
42+
"""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
n = int(input())
6+
lines = []
7+
for _ in range(n):
8+
x, y = map(int, input().split())
9+
lines.append([x, y])
10+
11+
lines.sort()
12+
13+
length = 0
14+
start, end = lines[0][0], lines[0][1]
15+
for i in range(1, n):
16+
if lines[i][0] <= end and lines[i][1] <= end: # 완전 겹치는 경우
17+
continue
18+
elif lines[i][0] <= end and lines[i][1] > end: # 약간 겹치는 경우 (끝점이 더 길 경우)
19+
end = lines[i][1]
20+
else: # 안 겹치는 경우
21+
length

0 commit comments

Comments
 (0)