민수 풀이
재현 풀이
송희 풀이
const fs = require("fs"); const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; const [nm, ...nums] = fs.readFileSync(filePath).toString().trim().split("\n"); let [n, m] = nm.split(" "); let square = 1; if (n == 1 || m == 1) return console.log(1); for (i = 0; i < +n - 1; i++) { for (j = 0; j < +m - 1; j++) { let topLeft = nums[i][j]; for (k = j + 1; k < +m; k++) { if (nums[i][k] == topLeft) { let length = +k - +j; if (nums[i + length] && nums[i + length][j] == topLeft && nums[i + length][k] == topLeft) { square = Math.max(square, (length + 1) ** 2); } } } } } console.log(square);
승민 풀이
let fs = require("fs"); //const [n, ...arr] = fs.readFileSync('/dev/stdin').toString().split('\n'); const [n, ...arr] = fs .readFileSync(__dirname + "/ex.txt") .toString() .split("\n"); let list = arr[0] .split(" ") .map(Number) .sort((a, b) => a - b); let result = 0; for (let i = 0; i < +n; i++) { let start = i; let end = +n - 1; while (start <= end) { let mid = ~~((start + end) / 2); if (list[i] >= list[mid] * 0.9) { start = mid + 1; } else { end = mid - 1; } } result += start - i - 1; } console.log(result);