일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- BFS
- dp
- 알고리즘
- socket
- ip
- javascript
- TCP
- typescript
- 타입 챌린지
- Node.js
- 쉬운 문제
- 프로그래머스
- 프로그래머스 레벨 2
- type challenge
- dfs
- HTTP 완벽 가이드
- 크롤링
- Algorithm
- 레벨 1
- Crawling
- 수학
- 타입스크립트
- 소켓
- HTTP
- 가천대
- 그래프
- Nestjs
- 문자열
- 백준
- 자바스크립트
- Today
- Total
목록백준 (100)
kakasoo
나는 이걸 틀려서, 결국 다른 사람의 코드를 참고했었다. 유명한 알고리즘이라 별도의 이름도 있다고 한다. LIS 라고 하는데, 말 그대로 Longest Increase Sequence? 뭐 그런 이름이었던 거 같다. 나는 이걸 짜기 위해서 n이 증가함에 따라 이전에 가능했던 수열에 새 값을 붙인 경우, 붙이지 않은 경우를 탐색했는데, 메모리 초과가 심각해서 풀 수가 없었다. DP는 DP 방법 말고는 답이 없는 듯 하다. 다음 문제가 가장 긴 감소하는 부분 수열인데,코드를 전혀 보지 않고 풀어보도록 하자. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process..
처음에는 대괄호, 소괄호를 따로 따로 배열을 만들어서 관리해 주었는데, 예외가 있었다. [(]) 형태로 들어올 때 제대로 동작하지 않았다. 그래서 배열을 하나로 합쳐줬더니 해결되었다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { if (line === ".") { rl.close(); } main(line); }).on("close", () => { process.exit(); }); /** * * @param {string} line */ const main = (line) =>..
부분 문자열, 부분 수열과 같다고 생각하면 되겠다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; const input = []; rl.on("line", (line) => { if (!count) { count = Number(line); } else { input.push(line); if (input.length === count) { main(line); rl.close(); } } }).on("close", () => { process.exit(); }); const factorial = (n..
그렇게 어려운 문제는 아니었다. 그냥 마이너스를 할 때, 최대한 크게 마이너스를 해주면 된다. 그래서 마이너스가 나오면 마이너스 뒤로 있는 모든 플러스를 우선시해줘서 빼야할 값을 크게 바꿔주면 된다. 그래서 -를 기준으로 문자열을 split 해주고, 각 요소들을 전부 더 해준다. 예를 들어 43 - 43 + 45 - 45가 라는 문자열이 있으면 ( 띄어쓰기는 원래 없어야 한다. ) 43,48,45 라는 숫자 배열로 바꿔주고, 앞에서부터 차례대로 빼주면 된다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line",..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; const input = [0]; rl.on("line", (line) => { if (!count) { count = Number(line); } else { input.push(Number(line)); if (input.length === count + 1) { main(); rl.close(); } } }).on("close", () => { process.exit(); }); const main = () => { const DP = new Arra..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let COUNT; let MAX_WEIGHT; let weights = [0]; let values = [0]; rl.on("line", (line) => { const arr = line.split(" ").map(Number); if (!COUNT && !MAX_WEIGHT) { COUNT = arr[0]; MAX_WEIGHT = arr[1]; } else { weights.push(arr[0]); values.push(arr[1]); if (weights.length > CO..
결코 신나지 않았다. 이게 Cpp였다면 솔직히 10분 안에 풀 자신도 있었다. 오류가 발생했다면 아마 다음과 같을 것이다. 배열에 string과 number를 혼용해서 쓰고 있지 않은가? 배열의 사이즈를 적절하게 하지 않아서 메모리가 초과되지 않았는가? 그냥 통째로 문자열로 다루려고 하지 않았는가? 예컨대, "111"를 키 값으로 저장한다던가... 이렇게 하면 문제가 발생한다. 다른 수, 예컨대 "1111"는 "1"과 "1"과 "11"의 조합인지, 아니면 11이 처음이나 중간에 나오는지 어떻게 구별하는가? 메모리가 꼬인다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, outp..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { main(line); rl.close(); }).on("close", () => { process.exit(); }); const dfs = (cur, max, value) => { if (cur === max) { console.log(value); process.exit(); } if (cur * 2
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { if (line === "0") { rl.close(); } main(line); }).on("close", () => { process.exit(); }); /** * * @param {string} line */ const main = (line) => { const numbers = line.split(""); while (numbers.length >= 2) { const pre = numbers.shift(); const bac..
const readline = require("readline"); const input = []; let count = 0; const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { if (!count) { count = 3 * line; } else { input.push(line); if (input.length % 3 === 0) { main(); } if (input.length === count) { rl.close(); } } }).on("close", () => { process.exit(); }); const main = () => { cons..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { main(Number(line)); rl.close(); }).on("close", () => { process.exit(); }); const main = (line) => { const DP = new Array(line + 1).fill(0); for (let i = 1; i
node.js로 푼 사람이 별로 없다는 게 참 슬픈 일이다. 자바스크립트로도 문제를 풀 수 있는데... 이 문제에서 주의할 것은 다음과 같다. ( 이 문제를 굳이 node.js로 검색했다면야... ) BigInt를 사용할 것. Cpp에서만 문제가 될 줄 알고 자만했는데, BigInt 때문에 틀린 것이었다. mod를 잊지 말 것. 나누라고 문제에 분명히 나와 있다. 혹시나 map 함수나 fill 등의 Array의 프로토타입 함수로 배열을 반환했다면, 모든 인덱스의 배열이 같은 배열을 가리키게 된다. 이 부분은 자바스크립트의 특성이므로 기억해두자. const readline = require("readline"); const rl = readline.createInterface({ input: process..