[BOJ] 2167 2차원 배열의 합

Time Lapse :10min 0sec

2167.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>

int main(void) {
int N, M, num, K;
int i, j , x, y;
int arr[301][301] = {0, };
scanf("%d %d",&N,&M);
for(int i=1; i<=N; i++)
for(int j=1; j<=M; j++){
scanf("%d",&num);
arr[i][j] = num + arr[i-1][j] + arr[i][j-1] - arr[i-1][j-1];
}
scanf("%d",&K);
for(int l = 0; l < K; l++){
scanf("%d %d %d %d",&i,&j,&x,&y);
printf("%d\n",arr[x][y] - arr[i-1][y] - arr[x][j-1] + arr[i-1][j-1]);
}
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2167/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.