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 | 31 |
Tags
- ์นด์นด์ค ์ฝํ
- ๋ฐฑ์ค 1339๋ฒ js
- suspense ๋ณ๋ชฉํ์
- emtion app router
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ์ค์ฝํ
- emotion RSC
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- js
- suspense react-query
- js ์ค์ฝํ
- next13 emotion
- suspense ๋์์๋ฆฌ
- ๊ตฌ๋ฆํค
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- ์ต์ ๋์ฒด์ด๋
- js ๋ฌธ์์ด ์์ถ
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- app router emotion
- suspense ๋น๋๊ธฐ
- ์ฌ์ฉ์ฑ ๊ฐ์
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- ๋ฐฑ์ค 2108 nodejs
Archives
- Today
- Total
Lennon FE
[๋ฐฑ์ค 1966๋ฒ] ํ๋ฆฐํฐ ํ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) ๋ณธ๋ฌธ
๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 1966๋ฒ] ํ๋ฆฐํฐ ํ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon 2022. 2. 15. 01:48728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/1966
const fs = require('fs');
const [n, ...input] = fs.readFileSync('dev/stdin').toString().trim().split('\n');
const result = input.map((v) => v.split(' ').map(Number));
let queue;
let answer = [];
while (result.length) {
queue = [];
const order = result.shift()[1];
const paperArr = result.shift().map((v, i) => [v, i]);
const len = paperArr.length;
while (queue.length !== len) {
if (paperArr[0][0] !== Math.max(...paperArr.map((v) => v[0]))) {
const a = paperArr.shift();
paperArr.push(a);
} else {
const a = paperArr.shift();
queue.push(a);
}
}
answer.push(queue.map((v) => v[1]).indexOf(order) + 1);
}
console.log(answer.join('\n'));
3
1 0
5
4 2
1 2 3 4 => [[1,0], [5], [4,2], [1,2,3,4], [6,0], [1,1,9,1,1,1]]
6 0 ex) 2๋ฒ์งธ ๊ฒฝ์ฐ
1 1 9 1 1 1 order = 2
paperArr = [[1,0], [2,1], [3,2], [4,2]]
์์ฒ๋ผ ์ ๋ ฅ๊ฐ์ ์กฐ์ ํ๊ณ , ์ต๋๊ฐ์ด ์๋๋ฉด ์์์ shiftํ๊ณ ๋ค๋ก ๋ค์ push, ์ต๋๊ฐ์ด๋ฉด queue๋ฐฐ์ด์ pushํ๋ค.
queue๋ฐฐ์ด์ด ์๋ณธ ๋ฐฐ์ด์ ๊ธธ์ด์ ๊ฐ์ด์ง๋ฉด ๋ฐ๋ณต๋ฌธ์ ์ข ๋ฃํ๊ณ ๋ฐฐ์ด์ 1๋ฒ์งธ ์ธ์๊ฐ order๊ฒ์ ์ฐพ์์ +1 ํด์ค ํ answer๋ฐฐ์ด์ pushํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ถ๋ ฅํด์ฃผ๋ฉด ๋!
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 17140๋ฒ] ์ด์ฐจ์ ๋ฐฐ์ด๊ณผ ์ฐ์ฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.17 |
---|---|
[๋ฐฑ์ค 1541๋ฒ] ์์ด๋ฒ๋ฆฐ ๊ดํธ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.15 |
[๋ฐฑ์ค 5430๋ฒ] AC - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.13 |
[๋ฐฑ์ค 1062๋ฒ] ๊ฐ๋ฅด์นจ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.11 |
[๋ฐฑ์ค 3085๋ฒ] ์ฌํ๊ฒ์ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.06 |
Comments