Skip to content

Commit 07b0347

Browse files
Merge pull request #689 from jinoo0306/main
[조진우] 104차 라이브 코테 제출
2 parents 64ec6e9 + f714991 commit 07b0347

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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(Number);
12+
13+
function solution(input) {
14+
const T = input[0];
15+
const N = input.slice(1);
16+
const dp = [];
17+
const result = [];
18+
dp[0] = 0;
19+
dp[1] = 1;
20+
dp[2] = 1;
21+
dp[3] = 1;
22+
dp[4] = 2;
23+
dp[5] = 2;
24+
25+
for (let i = 6; i <= Math.max(...N); i++) {
26+
dp[i] = dp[i - 1] + dp[i - 5];
27+
}
28+
29+
for (let i = 0; i < T; i++) {
30+
result[i] = dp[N[i]];
31+
}
32+
33+
return result.join("\n");
34+
}
35+
36+
console.log(solution(input));
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));
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function solution(begin, target, words) {
2+
let visit = [];
3+
let box = [];
4+
box.push([begin, 0]);
5+
6+
while (box.length > 0) {
7+
let now = box.shift();
8+
let txt = now[0];
9+
let cnt = now[1];
10+
11+
if (txt === target) {
12+
return cnt;
13+
}
14+
15+
for (let i = 0; i < words.length; i++) {
16+
let word = words[i];
17+
let diff = 0;
18+
for (let j = 0; j < word.length; j++) {
19+
if (txt[j] !== word[j]) {
20+
diff++;
21+
}
22+
}
23+
24+
if (diff === 1 && !visit.includes(word)) {
25+
visit.push(word);
26+
box.push([word, cnt + 1]);
27+
}
28+
}
29+
}
30+
31+
return 0;
32+
}

0 commit comments

Comments
 (0)