개발자 톡
연습문제 톡
스마트 물류
JS
- 등록일
- 2024-11-18 12:41:43
- 조회수
- 133
- 작성자
- vavoya6324
로봇 최대 20,000개
로봇 팔 길이 최대 10
로봇마다 좌우 확인 20
20,000 x 20 = 400,000
cpu 대충 1초에 1억 예상
0.004초
실제 0.04초
const fs = require('fs'); const input = fs.readFileSync('input.txt', 'utf8').trim().split(/\n+/); const [N, K] = input[0].split(/\s+/).map(Number); const line = input[1].split('') const robotIndexList = [] line.forEach((type, index) => { if (type === 'P') { robotIndexList.push(index) } }) let count = 0 robotIndexList.forEach((robotIndex) => { for (let start = robotIndex - K; start <= robotIndex + K; start++) { // 일단 범위 내 인지 검사 if (0 <= start && start < N) { // 물건 검사 if (line[start] === 'H') { count++ line[start] = 'X' break } } } }) console.log(count); // k = 2 예시 // 20 x 20,000
#스마트_물류
#js