๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 2167๋ฒˆ : 2์ฐจ์› ๋ฐฐ์—ด์˜ ํ•ฉ

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 7. 28.

 

 

Algorithm

-  2์ฐจ์› ๋ฐฐ์—ด์˜ ํ•ฉ -

 


 

๋ฌธ์ œ

2์ฐจ์› ๋ฐฐ์—ด์ด ์ฃผ์–ด์กŒ์„ ๋•Œ (i, j) ์œ„์น˜๋ถ€ํ„ฐ (x, y) ์œ„์น˜๊นŒ์ง€์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์ˆ˜๋“ค์˜ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๋ฐฐ์—ด์˜ (i, j) ์œ„์น˜๋Š” iํ–‰ j์—ด์„ ๋‚˜ํƒ€๋‚ธ๋‹ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

let fs = require("fs");
let input = fs.readFileSync("/dev/stdin")
	.toString()
	.trim()
	.split("\n")
	.map((el) => el.split(" ").map((el) => Number(el)));
let arr = input.splice(1, input[0][0]);
input.splice(0, 2);
let result = [];

for (let i = 0; i < input.length; i++) {
	let sum = 0;
	for (let j = Number(input[i][0]) - 1; j < Number(input[i][2]); j++) {
		for (let k = Number(input[i][1]) - 1; k < Number(input[i][3]); k++) {
			sum += arr[j][k];
		}
	}
	result.push(sum);
}

console.log(result.join('\n'));

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€