티스토리 뷰
https://www.acmicpc.net/problem/14890
14890번: 경사로
첫째 줄에 N (2 ≤ N ≤ 100)과 L (1 ≤ L ≤ N)이 주어진다. 둘째 줄부터 N개의 줄에 지도가 주어진다. 각 칸의 높이는 10보다 작거나 같은 자연수이다.
www.acmicpc.net
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split("\n");
function check(arr, N, L) {
let answer = 0;
for (let i = 0; i < N; i++) {
const now = arr[i];
let possible = 1;
for (let j = 1; j < N; j++) {
if (now[j - 1] == now[j]) possible++;
else if (now[j - 1] + 1 == now[j] && possible >= L) possible = 1;
else if (now[j - 1] == now[j] + 1 && possible >= 0) possible = 1 - L;
else { possible = -1; break };
}
if (possible >= 0) {
answer++;
}
}
return answer;
}
// 3, 3, 2, 1, 1, 1
// 1 2 - 1 - 1
function main(input) {
const board = input.map(v => v.split(' ').map(Number))
const [N, L] = board.shift()
let newBoard = Array.from(Array(N), () => Array(N));
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
newBoard[j][i] = board[i][j]
}
}
const res = check(board, N, L) + check(newBoard, N, L);
console.log(res)
}
main(input)
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js)백준 2234번: 성곽 (0) | 2022.04.03 |
---|---|
Node.js) 백준 1094번: 막대기 (0) | 2022.04.03 |
Node.js) 백준 17471번: 게리맨더링 (0) | 2022.04.03 |
Node.js) 백준 5338번: 마이크로소프트 로고 (0) | 2022.04.01 |
Node.js) 백준 1550번: 16진수 (0) | 2022.04.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 은둔청년체험
- 서버점검
- 동적프로그래밍
- 최소공통조상
- 투포인터
- 다이나밍프로그래밍
- create db
- 면접비
- 로드나인
- 서버개발
- 면접질문
- BFS
- 그래프
- 다이나믹프로그래밍
- 투포인터 연습
- node.js
- MOD
- create databases;
- MySQL
- KMP
- 롱베케이션
- 개발자면접
- DB 생성
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함