๐ŸŽฒ ๋ฐฑ์ค€ 16173๋ฒˆ ์ ํ”„์™• ์ฉฐ๋ฆฌ (Small)

Jeongeunยท2023๋…„ 5์›” 29์ผ
0

๋ฐฑ์ค€

๋ชฉ๋ก ๋ณด๊ธฐ
68/185

๋ฐฑ์ค€ 16173๋ฒˆ

๐Ÿ’Š ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ ๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.
๐Ÿ’Š ์ฒ˜์Œ์— ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”๋ฐ ์นธ์— 0์ด ์“ฐ์—ฌ์ง„ ๊ฒฝ์šฐ๋ฅผ ์ฒ˜๋ฆฌ๋ฅผ ์•ˆํ•ด์„œ ๋ฌดํ•œ ๋ฃจํ”„์— ๋น ์ ธ์„œ ๊ทธ๋Ÿฐ ๋“ฏ ํ•˜๋‹ค.

์ฝ”๋“œ

const fs = require('fs'); 
let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');

const N = +input.shift();
input = input.map((item) => item.split(" ").map(Number));

const checked = [];
const willCheck = [[0, 0]];
const dir = [
  [0, 1],
  [1, 0],
];

while (willCheck.length) {
  const [pointY, pointX] = willCheck.shift();
  if (!checked.includes([pointY, pointX])) {
    checked.push([pointY, pointX]);
    const count = input[pointY][pointX];
    if (count !== 0) {
      for (let i = 0; i < 2; i++) {
        const nextY = pointY + dir[i][0] * count;
        const nextX = pointX + dir[i][1] * count;

        if (nextY === N - 1 && nextX === N - 1) {
          return console.log("HaruHaru");
        }

         if (nextX < N && nextY < N) {
          willCheck.push([nextY, nextX]);
        }
      }
    }
  }
}

console.log("Hing");

0๊ฐœ์˜ ๋Œ“๊ธ€