❗ 풀이 과정
🤜 풀이코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int T = Integer.parseInt(st.nextToken());
int [][] map = new int [N+1][N+1];
for(int i=0;i<=N;i++) {
map[i][0]=0;
map[0][i]=0;
}
for(int h=1;h<=N;h++) {
st = new StringTokenizer(br.readLine());
for(int w=1;w<=N;w++) {
map[h][w]=Integer.parseInt(st.nextToken());
map[h][w]= map[h][w]+map[h-1][w]+map[h][w-1]-map[h-1][w-1];
}
}
for(int t=0;t<T;t++) {
int sum=0;
st = new StringTokenizer(br.readLine());
int x1 =Integer.parseInt(st.nextToken()); int y1 =Integer.parseInt(st.nextToken()); int x2 =Integer.parseInt(st.nextToken()); int y2 =Integer.parseInt(st.nextToken());
System.out.println(map[x2][y2]-map[x1-1][y2]-map[x2][y1-1]+map[x1-1][y1-1]);
}
}
}