Baekjoon - 11660

Tadap·2023년 11월 11일
0

Baekjoon

목록 보기
80/94
post-custom-banner

문제

Solved.ac Class4

1차시도

public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String[] split = br.readLine().split(" ");
        int size = Integer.parseInt(split[0]);
        int answerCount = Integer.parseInt(split[1]);

        int[][] data = new int[size + 1][size + 1];
        for (int i = 1; i < size + 1; i++) {
            split = br.readLine().split(" ");
            for (int j = 1; j < size + 1; j++) {
                data[i][j] = Integer.parseInt(split[j - 1]);
            }
        }


        for (int i = 1; i < size + 1; i++) {
            int temp = data[i][1];
            for (int j = 2; j < size + 1; j++) {
                temp = temp + data[i][j];
                data[i][j] = temp;
            }
        }

        for (int i = 0; i < answerCount; i++) {
            int sum = 0;
            String[] replyData = br.readLine().split(" ");
            int startX = Integer.parseInt(replyData[0]);
            int startY = Integer.parseInt(replyData[1]);
            int endX = Integer.parseInt(replyData[2]);
            int endY = Integer.parseInt(replyData[3]);

            for (int j = startX; j <endX + 1; j++) {
                sum = sum + (data[j][endY] - data[j][startY - 1]);
            }
            sb.append(sum).append("\n");
        }

        System.out.println(sb);
    }
}

성공

post-custom-banner

0개의 댓글