728x90
https://www.acmicpc.net/problem/11660
import sys
input = sys.stdin.readline
graph = []
N, M = map(int, input().split(" "))
dp = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
A = list(map(int, input().rstrip().split(" ")))
graph.append(A)
for i in range(1, N + 1):
for j in range(1, N + 1):
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + graph[i - 1][j - 1]
for j in range(M):
x1, y1, x2, y2 = map(int, input().split(" "))
answer = dp[x2][y2] - dp[x2][y1 - 1] - dp[x1 - 1][y2] + dp[x1 - 1][y1 - 1]
print(answer)
728x90
'Study > Coding Test' 카테고리의 다른 글
[백준] 14940 - 쉬운 최단거리 Python (0) | 2023.07.04 |
---|---|
[백준] 1940 - 연속합 Python (0) | 2023.06.29 |
[백준] 18428 - 감시 피하기 Python (0) | 2023.06.28 |
[백준] 11053 - 가장 긴 증가하는 부분 수열 Python (0) | 2023.06.27 |
[백준] 5430 - AC Python (0) | 2023.06.05 |