Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

최주은 / 16주차 #23

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5f01b7a
[BOJ] 예산 / 실버3 / 30분
jee-woo Mar 29, 2023
daf04d1
[BOJ] 나무 자르기 / 실버2 / 15분
jee-woo Mar 29, 2023
48e89f2
[BOJ] 랜선 자르기 / 실버2 / 1시간
jee-woo Mar 29, 2023
44a4272
IF문 좀 대신 써줘 / 실버3 / 1시간
jee-woo Mar 29, 2023
5a5e007
용돈 관리 / 실버2 / 1시간
jee-woo Mar 29, 2023
2f6ea9a
[BOJ] 안전 영역 / 실버1 / 20분
jee-woo Apr 5, 2023
5ee1503
[BOJ] 유기농 배추 / 실버2 / 1시간
jee-woo Apr 5, 2023
025d226
[BOJ] 연결 요소의 개수 / 실버2 / 1시간
jee-woo Apr 5, 2023
65bf5ad
[BOJ] 경로 찾기 / 실버1 / 1시간
jee-woo Apr 5, 2023
e7101e5
[BOJ] DOM / 실버2 / 40분
jee-woo Apr 5, 2023
f657d4c
[BOJ] DFS와 BFS / 실버2 / 1시간
jee-woo Apr 11, 2023
5478484
[BOJ] 유기농 배추 / 실버2 / 30분
jee-woo Apr 26, 2023
e7ca103
[BOJ] 촌수 계산 / 실버2 / 1시간
jee-woo Apr 26, 2023
49217fb
[BOJ] 미로 탐색 / 실버1 / 30분~1시간
jee-woo Apr 26, 2023
f640652
[BOJ] 나이트의 이동 / 실버1 / 30분
jee-woo Apr 26, 2023
dd55f3d
[BOJ] 2xn 타일링 / 실버3 / 15분
jee-woo May 3, 2023
5b9ddcd
[BOJ] 01타일 / 실버3 / 25분
jee-woo May 3, 2023
536a159
[BOJ] 돌 게임 / 실버5 / 20분
jee-woo May 3, 2023
c0de78d
[BOJ] 이친수 / 실버3 / 20분
jee-woo May 3, 2023
c8830d4
[BOJ] 1로 만들기 / 실버3 / 20분
jee-woo May 3, 2023
6473362
[BOJ] 진우의 달 여행 (Small) / 실버3 / 1시간 이내
jee-woo May 10, 2023
9566e70
[BOJ] 연속합 / 실버2 / 30분
jee-woo May 10, 2023
972914b
[BOJ] 부분수열의 합 / 실버2 / 30분 이상
jee-woo May 10, 2023
db5c204
[BOJ] 사탕 게임 / 실버2 / 1시간 이내 (레퍼런스 참고)
jee-woo May 10, 2023
dee1a5a
[BOJ] 숫자 야구 / 실버3 / 1시간 이상
jee-woo May 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions jueun/week17/2468.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const fs = require("fs");
const input = fs
.readFileSync(
process.platform === "linux" ? "/dev/stdin" : __dirname + "/2468.txt"
)
.toString()
.split("\n")
.map((el) => el.split(" ").map(Number));

const N = input[0][0];
const map = input.slice(1);

const solution = (n, map) => {
let maxCount = 0;

let visited = new Array(n);
for (let i = 0; i < n; i++) visited[i] = new Array(n).fill(false);

const dfs = (i, j, height) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 각 방향마다 dfs 함수를 호출하는 방법도 있네요

visited[i][j] = true;
if (map[i - 1]?.[j] >= height && !visited[i - 1]?.[j])
dfs(i - 1, j, height);
if (map[i + 1]?.[j] >= height && !visited[i + 1]?.[j])
dfs(i + 1, j, height);
if (map[i]?.[j - 1] >= height && !visited[i]?.[j - 1])
dfs(i, j - 1, height);
if (map[i]?.[j + 1] >= height && !visited[i]?.[j + 1])
dfs(i, j + 1, height);
};

let count;
for (let rainfall = 1; rainfall <= 100; rainfall++) {
count = 0;
visited = new Array(n);
for (let i = 0; i < n; i++) visited[i] = new Array(n).fill(false);

for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (map[i][j] >= rainfall && !visited[i][j]) {
dfs(i, j, rainfall);
count++;
}
}
}
maxCount = Math.max(maxCount, count);
if (count === 0) break;
}

return maxCount;
};

console.log(solution(N, map));