Skip to content

Commit 0749c86

Browse files
Merge pull request #526 from eric-hjh/main
[황장현] 65차 라이브 코테 제출
2 parents 3ab4af4 + cd56dc8 commit 0749c86

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

live6/test65/문제1/황장현.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 board = input.slice(1).map((row) => row.split(''));
10+
let max = 0;
11+
12+
function getMaxCandy(board) {
13+
let maxLength = 0;
14+
15+
for (let i = 0; i < N; i++) {
16+
let count = 1;
17+
for (let j = 1; j < N; j++) {
18+
if (board[i][j] === board[i][j - 1]) {
19+
count++;
20+
} else {
21+
maxLength = Math.max(maxLength, count);
22+
count = 1;
23+
}
24+
}
25+
maxLength = Math.max(maxLength, count);
26+
}
27+
28+
for (let j = 0; j < N; j++) {
29+
let count = 1;
30+
for (let i = 1; i < N; i++) {
31+
if (board[i][j] === board[i - 1][j]) {
32+
count++;
33+
} else {
34+
maxLength = Math.max(maxLength, count);
35+
count = 1;
36+
}
37+
}
38+
maxLength = Math.max(maxLength, count);
39+
}
40+
41+
return maxLength;
42+
}
43+
44+
for (let i = 0; i < N; i++) {
45+
for (let j = 0; j < N; j++) {
46+
if (j + 1 < N) {
47+
[board[i][j], board[i][j + 1]] = [board[i][j + 1], board[i][j]];
48+
max = Math.max(max, getMaxCandy(board));
49+
[board[i][j], board[i][j + 1]] = [board[i][j + 1], board[i][j]];
50+
}
51+
52+
if (i + 1 < N) {
53+
[board[i][j], board[i + 1][j]] = [board[i + 1][j], board[i][j]];
54+
max = Math.max(max, getMaxCandy(board));
55+
[board[i][j], board[i + 1][j]] = [board[i + 1][j], board[i][j]];
56+
}
57+
}
58+
}
59+
60+
return max;
61+
}
62+
63+
console.log(solution(input));

live6/test65/문제2/황장현.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 N = input[0][0];
10+
const schedule = input.slice(1);
11+
const dp = new Array(N).fill(0);
12+
for (let i = 0; i < N; i++) {
13+
const [duration, profit] = schedule[i];
14+
15+
if (i + duration > N) {
16+
continue;
17+
}
18+
dp[i] += profit;
19+
20+
for (let j = i + duration; j < N; j++) {
21+
dp[j] = Math.max(dp[j], dp[i]);
22+
}
23+
}
24+
return Math.max(...dp);
25+
}
26+
27+
console.log(solution(input));

live6/test65/문제3/황장현.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function solution(s) {
2+
const stack = [];
3+
4+
for (let i = 0; i < s.length; i++) {
5+
if (stack[stack.length - 1] === s[i]) {
6+
stack.pop();
7+
} else {
8+
stack.push(s[i]);
9+
}
10+
}
11+
12+
return !stack.length ? 1 : 0;
13+
}
14+
15+
console.log(solution('baabaa'));

0 commit comments

Comments
 (0)