[백준 11660] 구간 합 구하기 5

rhkr9080·2023년 7월 11일
0

BOJ(백준)

목록 보기
16/19

문제링크 : https://www.acmicpc.net/problem/11660

💻 문제 풀이 : C++

	#include <iostream>

	using namespace std;

	// int N_MAP[1050][1050];
	int SUM_MAP[1050][1050];

	int main()
	{
		ios::sync_with_stdio(0);
		cin.tie(0);

		int N, M;
		cin >> N >> M;

		int cnt = 0;
		for (int i = 1; i <= N; i++)
		{
			for (int j = 1; j <= N; j++)
			{
				cin >> cnt;
				// cin >> N_MAP[i][j];
				// SUM_MAP[i][j] = N_MAP[i][j] + SUM_MAP[i-1][j] + SUM_MAP[i][j-1] - SUM_MAP[i-1][j-1];
				SUM_MAP[i][j] = cnt + SUM_MAP[i - 1][j] + SUM_MAP[i][j - 1] - SUM_MAP[i - 1][j - 1];
			}

		}
		for (int i = 0; i < M; i++)
		{
			int r1, c1, r2, c2;
			cin >> r1 >> c1 >> r2 >> c2;
			// cout << SUM_MAP[r2][c2] - SUM_MAP[r2][c1-1] - SUM_MAP[r1-1][c2] + SUM_MAP[r1 - 1][c1 - 1] << endl;
			cout << SUM_MAP[r2][c2] - SUM_MAP[r2][c1 - 1] - SUM_MAP[r1 - 1][c2] + SUM_MAP[r1 - 1][c1 - 1] << "\n";
		}


		return 0;
	}

📌 memo 😊
백준(BOJ)문제 풀이 시 개행은 "\n"으로...

cout << endl;

why??
=> endl의 경우 flush() 함수를 겸하기 때문에 출력버퍼를 지워주는 과정이 추가됨


ref)
👍이해 굳
https://chanhuiseok.github.io/posts/baek-19/
⭐ endl 설명
https://cocoon1787.tistory.com/135

profile
공부방

0개의 댓글