Skip to content

Commit f691920

Browse files
Merge pull request #532 from egg-silver/main
[이지은] 66차 라이브코테 제출
2 parents f9dac99 + 9ff10bd commit f691920

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

live6/test66/문제1/이지은.js

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(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((a) => a.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const n = input[0][0];
10+
const arr = input.slice(1);
11+
const count = { '-1': 0, 0: 0, 1: 0 };
12+
13+
function check(x, y, size) {
14+
const first = arr[x][y];
15+
for (let i = x; i < x + size; i++) {
16+
for (let j = y; j < y + size; j++) {
17+
if (arr[i][j] !== first) {
18+
return false;
19+
}
20+
}
21+
}
22+
return true;
23+
}
24+
25+
function divide(x, y, size) {
26+
if (check(x, y, size)) {
27+
count[arr[x][y]]++;
28+
} else {
29+
const newSize = size / 3;
30+
for (let i = 0; i < 3; i++) {
31+
for (let j = 0; j < 3; j++) {
32+
divide(x + i * newSize, y + j * newSize, newSize);
33+
}
34+
}
35+
}
36+
}
37+
38+
divide(0, 0, n);
39+
40+
return `${count['-1']}\n${count['0']}\n${count['1']}`;
41+
}
42+
43+
console.log(solution(input));

live6/test66/문제2/이지은.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((a) => a.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const n = input[0][0];
10+
const arr = input.slice(1);
11+
const visited = Array.from({ length: n }, () => Array(n).fill(false));
12+
13+
const directions = [
14+
[0, 1],
15+
[1, 0],
16+
];
17+
18+
let isReachable = false;
19+
20+
function dfs(x, y) {
21+
if (x === n - 1 && y === n - 1) {
22+
isReachable = true;
23+
return;
24+
}
25+
26+
visited[x][y] = true;
27+
const step = arr[x][y];
28+
29+
for (const [dx, dy] of directions) {
30+
const nx = x + dx * step;
31+
const ny = y + dy * step;
32+
33+
if (
34+
nx >= 0 &&
35+
ny >= 0 &&
36+
nx < n &&
37+
ny < n &&
38+
!visited[nx][ny] &&
39+
arr[nx][ny] !== 0
40+
) {
41+
dfs(nx, ny);
42+
}
43+
}
44+
}
45+
46+
dfs(0, 0);
47+
48+
return isReachable ? 'HaruHaru' : 'Hing';
49+
}
50+
51+
console.log(solution(input));

live6/test66/문제3/이지은.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function solution(n, a, b) {
2+
let round = 0;
3+
4+
while (a !== b) {
5+
a = Math.ceil(a / 2);
6+
b = Math.ceil(b / 2);
7+
round++;
8+
}
9+
10+
return round;
11+
}
12+
13+
console.log(solution(8, 4, 7));

0 commit comments

Comments
 (0)