From b20e0480dc7437caf24a584d9d34141e81fdabcc Mon Sep 17 00:00:00 2001 From: Yeseul Lee Date: Sat, 18 Nov 2023 01:09:19 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=9D=B4=EC=98=88=EC=8A=AC]=203=EC=A3=BC?= =?UTF-8?q?=EC=B0=A8=20=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\203\235 \354\210\230\354\227\264.js" | 29 ++++++++++ ...\354\246\210 4\353\270\224\353\237\255.js" | 56 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 "lys/\354\212\244\355\203\235 \354\210\230\354\227\264.js" create mode 100644 "lys/\355\224\204\353\240\214\354\246\210 4\353\270\224\353\237\255.js" diff --git "a/lys/\354\212\244\355\203\235 \354\210\230\354\227\264.js" "b/lys/\354\212\244\355\203\235 \354\210\230\354\227\264.js" new file mode 100644 index 0000000..1a54583 --- /dev/null +++ "b/lys/\354\212\244\355\203\235 \354\210\230\354\227\264.js" @@ -0,0 +1,29 @@ + +//const input = fs.readFileSync("/dev/stdin").toString().trim().split('\n').map(Number); +const fs = require('fs'); +const input = fs.readFileSync('lys/input.txt', 'utf-8').trim().split('\n').map(Number); +const n = input.shift(); +const answerStack = []; +const stack = []; +let num = 1; + +for (let i = 0; i < n; i++) { + const targetNum = input[i]; + + while (num <= targetNum) { + stack.push(num); + num++; + answerStack.push("+"); + } + + const poppedNum = stack.pop(); + answerStack.push("-"); + + if (poppedNum !== targetNum) { + answerStack.length = 0; + answerStack.push("NO"); + break; + } +} + +console.log(answerStack.join("\n")); diff --git "a/lys/\355\224\204\353\240\214\354\246\210 4\353\270\224\353\237\255.js" "b/lys/\355\224\204\353\240\214\354\246\210 4\353\270\224\353\237\255.js" new file mode 100644 index 0000000..f9faffe --- /dev/null +++ "b/lys/\355\224\204\353\240\214\354\246\210 4\353\270\224\353\237\255.js" @@ -0,0 +1,56 @@ +function solution(m, n, board) { + let removedBlocks = []; + const Board = []; + let index = 0; + let totalRemoved = 0; + + board.forEach((row) => Board.push(row.split(""))); + + while (true) { + for (let i = 0; i < m - 1; i++) { + for (let j = 0; j < n; j++) { + if ( + Board[i][j] !== '0' && + Board[i][j] === Board[i][j + 1] && + Board[i][j + 1] === Board[i + 1][j] && + Board[i + 1][j] === Board[i + 1][j + 1] + ) { + removedBlocks.push([i, j], [i, j + 1], [i + 1, j], [i + 1, j + 1]); + } + } + } + + if (removedBlocks.length === 0) break; + + removedBlocks.forEach((block) => (Board[block[0]][block[1]] = '0')); + removedBlocks = []; + + for (let i = 1; i < m; i++) { + for (let j = 0; j < n; j++) { + if (Board[i][j] === '0') { + Board[i][j] = Board[i - 1][j]; + + if (i - 2 >= 0 && Board[i - 2][j] !== '0') { + index = i; + while (index - 2 >= 0) { + Board[index - 1][j] = Board[index - 2][j]; + Board[index - 2][j] = '0'; + index--; + } + } else { + Board[i - 1][j] = '0'; + } + } + } + } + } + + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + if (Board[i][j] === '0') { + totalRemoved++; + } + } + } + return totalRemoved; +}