Skip to content

Commit ca574f7

Browse files
Merge pull request #688 from eric-hjh/main
[황장현] 104차 라이브 코테 제출
2 parents 07b0347 + 31fb661 commit ca574f7

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const T = input[0][0];
10+
const nums = input.slice(1);
11+
const dp = Array(101).fill(0);
12+
13+
dp[1] = 1;
14+
dp[2] = 1;
15+
dp[3] = 1;
16+
dp[4] = 2;
17+
dp[5] = 2;
18+
19+
for (let i = 6; i <= 100; i++) {
20+
dp[i] = dp[i - 1] + dp[i - 5];
21+
}
22+
23+
return nums.map((n) => dp[n]).join('\n');
24+
}
25+
26+
console.log(solution(input));
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(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n');
6+
7+
function solution(input) {
8+
const N = Number(input[0]);
9+
const relations = input.slice(1).map((line) => line.split(''));
10+
11+
let max = 0;
12+
13+
for (let i = 0; i < N; i++) {
14+
const set = new Set();
15+
16+
for (let j = 0; j < N; j++) {
17+
if (i === j) continue;
18+
19+
if (relations[i][j] === 'Y') {
20+
set.add(j);
21+
} else {
22+
for (let k = 0; k < N; k++) {
23+
if (relations[i][k] === 'Y' && relations[k][j] === 'Y') {
24+
set.add(j);
25+
break;
26+
}
27+
}
28+
}
29+
}
30+
31+
max = Math.max(max, set.size);
32+
}
33+
return max;
34+
}
35+
36+
console.log(solution(input));
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function solution(begin, target, words) {
2+
if (!words.includes(target)) return 0;
3+
4+
const queue = [[begin, 0]];
5+
const visited = new Set();
6+
7+
function canTransform(word1, word2) {
8+
let diffCount = 0;
9+
10+
for (let i = 0; i < word1.length; i++) {
11+
if (word1[i] !== word2[i]) diffCount++;
12+
if (diffCount > 1) return false;
13+
}
14+
15+
return diffCount === 1;
16+
}
17+
18+
while (queue.length) {
19+
const [current, count] = queue.shift();
20+
21+
if (current === target) return count;
22+
23+
for (const word of words) {
24+
if (!visited.has(word) && canTransform(current, word)) {
25+
visited.add(word);
26+
queue.push([word, count + 1]);
27+
}
28+
}
29+
}
30+
31+
return 0;
32+
}
33+
34+
console.log(solution('hit', 'cog', ['hot', 'lot', 'dog', 'dot', 'log', 'cog']));

0 commit comments

Comments
 (0)