티스토리 뷰

 

 

const input = require('fs')
	.readFileSync('./dev/stdin')
	.toString()
	.trim()
	.split('\n')
	.map((v) => v.split(' ').map(Number));
const [N, M] = input.shift();

const board = [];

for (let i = 0; i < N; i++) {
	board.push(input.shift());
}

let dp = Array.from(Array(N + 1), () => Array(N + 1).fill(0));

for (let i = 1; i <= N; i++) {
	for (let j = 1; j <= N; j++) {
		dp[i][j] = board[i - 1][j - 1] + dp[i][j - 1] - dp[i - 1][j - 1] + dp[i - 1][j];
	}
}

const answer = [];

input.forEach((v) => {
	const [x1, y1, x2, y2] = v;

	const sum = dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1];

	answer.push(sum);
});

console.log(answer.join('\n'));
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함