Skip to content

Commit 0e69dcc

Browse files
committed
104차 2번 문제풀이
1 parent 55246b3 commit 0e69dcc

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const input = require("fs")
2+
.readFileSync(
3+
process.platform === "linux"
4+
? "/dev/stdin"
5+
: require("path").join(__dirname, "input.txt"),
6+
"utf8"
7+
)
8+
.toString()
9+
.trim()
10+
.split("\n")
11+
.map((line) => line.split(""));
12+
13+
function solution(input) {
14+
const N = Number(input[0].join(""));
15+
const friends = input.slice(1);
16+
let maxCount = 0;
17+
18+
for (let i = 0; i < N; i++) {
19+
const visited = Array(N).fill(false);
20+
21+
for (let j = 0; j < N; j++) {
22+
if (i === j) continue;
23+
24+
if (friends[i][j] === "Y") {
25+
visited[j] = true;
26+
} else {
27+
for (let k = 0; k < N; k++) {
28+
if (friends[i][k] === "Y" && friends[k][j] === "Y") {
29+
visited[j] = true;
30+
break;
31+
}
32+
}
33+
}
34+
}
35+
36+
const count = visited.filter(Boolean).length;
37+
maxCount = Math.max(maxCount, count);
38+
}
39+
40+
return maxCount;
41+
}
42+
43+
console.log(solution(input));

0 commit comments

Comments
 (0)