개발자 톡

연습문제 톡 장애물 인식 프로그램

장애물 인식 프로그램 js

등록일
2023-08-03 17:18:36
조회수
447
작성자
poboo99

tc1, 2, 5를 빼면 다 오답인데 어디서 틀린 건지 감이 안오네요 ㅠㅠ 반례 찾아주시면 감사하겠습니다!!


const fs = require('fs');

const input = fs.readFileSync('/dev/stdin').toString().trim().split("\n").map(e => e.split("").map(Number));
const N = input.shift();
const dx = [-1, 1, 0, 0];
const dy = [0, 0, -1, 1];
const result = [];

const bfs = (x, y) => {
    let count = 0;

    const queue = [];
    queue.push([x, y]);
    input[x][y] = 0;

    while(queue.length) {
        const [x, y] = queue.shift();
        count += 1;
        
        for(let i = 0; i<4; i++) {
            const moveX = x + dx[i];
            const moveY = y + dy[i];
        
            if(moveX >= 0 && moveX < N && moveY >= 0 && moveY < N && input[moveX][moveY] === 1) {
                queue.push([moveX, moveY]);
                input[moveX][moveY] = 0;
                
            }
        }
    }

    return count;
}

for(let x = 0; x a - b).join('\n'))



#장애물_인식_프로그램
#javascript
#반례

이 카테고리의 톡 더보기