Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Tags
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- emotion RSC
- suspense ๋ณ๋ชฉํ์
- ์ฌ์ฉ์ฑ ๊ฐ์
- ๋ฐฑ์ค 1339๋ฒ js
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๊ตฌ๋ฆํค
- ์ค์ฝํ
- ๋ฐฑ์ค 2108 nodejs
- app router emotion
- suspense ๋์์๋ฆฌ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- ์ต์ ๋์ฒด์ด๋
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- suspense react-query
- emtion app router
- js
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- js ์ค์ฝํ
- js ๋ฌธ์์ด ์์ถ
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- next13 emotion
- ์นด์นด์ค ์ฝํ
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- suspense ๋น๋๊ธฐ
Archives
- Today
- Total
Lennon FE
[๋ฐฑ์ค 3085๋ฒ] ์ฌํ๊ฒ์ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) ๋ณธ๋ฌธ
๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 3085๋ฒ] ์ฌํ๊ฒ์ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon 2022. 2. 6. 20:26728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/3085
const fs = require('fs');
let [len, ...input] = fs
.readFileSync('dev/stdin')
.toString()
.trim()
.split('\n')
.map((v) => v.split(''));
len = +len.join('');
let MAX = eatCandyCount(input);
for (let i = 0; i < len; i++) {
for (let j = 0; j < len - 1; j++) {
if (input[i][j] !== input[i][j + 1]) {
[input[i][j], input[i][j + 1]] = [input[i][j + 1], input[i][j]];
MAX = Math.max(MAX, eatCandyCount(input));
[input[i][j + 1], input[i][j]] = [input[i][j], input[i][j + 1]];
}
}
} // ์ข์ฐ ๊ฐ์ด ๋ค๋ฅด๋ฉด ๊ฐ ๋ฐ๊ฟ์ฃผ๊ณ ์บ๋ ๊ฐ์ ์ธ๊ณ ๋ค์ ๋ณธ๋์ ๊ฐ์ผ๋ก ๋ฐ๊ฟ์ฃผ๊ธฐ
for (let i = 0; i < len - 1; i++) {
for (let j = 0; j < len; j++) {
if (input[i][j] !== input[i + 1][j]) {
[input[i][j], input[i + 1][j]] = [input[i + 1][j], input[i][j]];
MAX = Math.max(MAX, eatCandyCount(input));
[input[i + 1][j], input[i][j]] = [input[i][j], input[i + 1][j]];
}
}
} // ์ํ ๊ฐ์ด ๋ค๋ฅด๋ฉด ๊ฐ ๋ฐ๊ฟ์ฃผ๊ณ ์บ๋์ธ๊ณ ๋ค์ ๋ณธ๋์ ๊ฐ์ผ๋ก ๋ฐ๊ฟ์ฃผ๊ธฐ
console.log(MAX); // ์ต๋๊ฐ ์ถ๋ ฅ
function eatCandyCount(arr) {
let MAX = 0;
for (let i = 0; i < len; i++) {
let count = 0;
let value = arr[i][0];
for (let j = 0; j < len; j++) {
if (arr[i][j] === value) {
count++;
} else {
MAX = Math.max(MAX, count);
count = 1;
value = arr[i][j];
}
if (j === len - 1) MAX = Math.max(MAX, count);
}
} // ํ์ผ๋ก ๋๋ฉด์ ์ฐ์๋ ๊ฐ์ ์ฌํ ๊ฐ์ ์ธ๊ธฐ
for (let i = 0; i < len; i++) {
let count = 0;
let value = arr[0][i];
for (let j = 0; j < len; j++) {
if (arr[j][i] === value) {
count++;
} else {
MAX = Math.max(MAX, count);
count = 1;
value = arr[j][i];
}
if (j === len - 1) MAX = Math.max(MAX, count);
}
} // ์ด๋ก ๋๋ฉด์ ์ฐ์๋ ๊ฐ์ ์ฌํ ๊ฐ์ ์ธ๊ธฐ
return MAX; // ๊ฐ์ฅ ํฐ ๊ฐ return
}
์ข์ฐ ์ฌํ ์์ด ๋ค๋ฅด๊ฑฐ๋, ์ํ ์ฌํ ์์ด ๋ค๋ฅด๋ฉด ๋ ๊ฐ์ ๋ฐ๊ฟ์ฃผ๊ณ
[input[i][j], input[i][j + 1]] = [input[i][j + 1], input[i][j]];
eatCandyCount ํจ์๋ฅผ ํธ์ถํด ์ต๋ ๊ฐ์๋ฅผ ์ธ๊ณ ๋ค์ ๋ณธ๋ ๋ฐฐ์ด๋๋ก ๋ ๊ฐ์ ๋ฐ๊ฟ์ค๋ค.
[input[i][j + 1], input[i][j]] = [input[i][j], input[i][j + 1]];
๋๊น์ง ์ํํ์ฌ ์ต๋๊ฐ์ ๊ตฌํ๋ฉด ๋!
์ฒ์์ ๋ฐฐ์ด์๋ค๊ฐ ๊ฐ์ ๋ฃ๊ณ ํ์ Math.max ํจ์๋ฅผ ์ด์ฉํด ํธ์ถํ์ง๋ง ์๊ฐํด๋ณด๋ ๊ทธ๋ฅ ์ฒ์๋ถํฐ Max๊ฐ์ ์์ ํด๊ฐ๋ฉฐ ๋์ค์ ๊ฐ์ ์ถ๋ ฅํ๋ ๊ฒ ์๊ฐ๋ณต์ก๋, ๋ฉ๋ชจ๋ฆฌ์์ ํจ์จ์ ์ด๋ค.
์ค์ ๋ก ๋ฉ๋ชจ๋ฆฌ ๋ฐ ์๊ฐ์์ ํจ์ฌ ์ ์ฉํ ๊ฑธ ํ์ธํ ์ ์์๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 5430๋ฒ] AC - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.13 |
---|---|
[๋ฐฑ์ค 1062๋ฒ] ๊ฐ๋ฅด์นจ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.11 |
[๋ฐฑ์ค 6603๋ฒ] ๋ก๋ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.06 |
[๋ฐฑ์ค 1920๋ฒ] ์ ์ฐพ๊ธฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.03 |
[๋ฐฑ์ค 10816๋ฒ] ์ซ์ ์นด๋2 - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.03 |
Comments