문제
1 체크카드


2 단풍나무



3 거리두기



4 주차 구역 나누기


풀이
효성
1
const readline = require('readline'); (async () => { let rl = readline.createInterface({ input: process.stdin }); const inputs = []; rl.on('line', (line) => inputs.push(line.trim().split(' '))).on( 'close', () => { main(inputs); process.exit(); } ); })(); function main(data) { const [n, m] = data.shift(); let total = +(n); let willPay = []; const payFromWillPay = () => { while(willPay.length && willPay[0] <= total) { const pay = willPay.shift(); total -= pay; } } data.forEach(d => { const [type, Amount] = d; const amount = +(Amount); if(type === 'deposit') { total += amount; } else if(type === 'pay') { if(total >= amount) { total -= amount; } } else if(type === 'reservation') { willPay.push(amount); } payFromWillPay(); }); console.log(total); }
2
const readline = require('readline'); (async () => { const rl = readline.createInterface({ input: process.stdin }); const inputs = []; rl.on('line', function (line) { inputs.push(line); }).on('close', function () { main(inputs); process.exit(); }); })(); function main(data) { const board = []; const dir = [ [-1, 0], [0, 1], [1, 0], [0, -1], ]; let answer = 0; const n = data.shift(); data.forEach(d => { const splited = d.split(' ').map(v => +v); board.push(splited); }); const isAllChanged = () => { for(let i = 0; i < n; i++) { for(let j = 0; j < n; j++) { if(board[i][j] !== 0) { return false; } } } return true; } const check = () => { answer += 1; const change_list = []; for(let i = 0; i < n; i++) { for(let j = 0; j < n; j++) { if(board[i][j] === 0) { continue; } let nearChangedCnt = 0; for(let k = 0; k < dir.length; k++) { const [x, y] = dir[k]; const nr = i + x; const nc = j + y; if(nr < 0 || nr >= n || nc < 0 || nc >= n) { continue; } if(board[nr][nc] === 0) { nearChangedCnt += 1; } } const value = Math.max(board[i][j] - nearChangedCnt, 0); change_list.push([i, j, value]); } } for(const change of change_list) { const [r, c, val] = change; board[r][c] = val; } } while(!isAllChanged()) { check(); } console.log(answer); }
3
재영
아진짜 문자열 변환 저질…입니다… 낄낄…후후…
// Run by Node.js const readline = require('readline'); (async () => { let rl = readline.createInterface({ input: process.stdin }); const inputs = []; rl.on('line', (line) => inputs.push(line.trim().split(' '))).on( 'close', () => { main(inputs); process.exit(); } ); })(); class Queue { constructor() { this.queue = []; this.front = 0; this.rear = 0; } enqueue(value) { this.queue[this.rear] = value; this.rear += 1; } dequeue() { const value = this.queue[this.front]; delete this.queue[this.front]; this.front += 1; return value; } get head() { return this.queue[this.front]; } get length() { return this.rear - this.front; } } function main(inputs) { const [N, M] = inputs[0]; let result = +N; const queue = new Queue(); for (let i = 0; i < +M; i += 1) { const [command, money] = inputs[i + 1]; const moneyNumber = Number(money); if (command === 'deposit') { result += moneyNumber; } else if (command === 'pay') { if (result < moneyNumber) continue; result -= moneyNumber; } else { queue.enqueue(moneyNumber); } while (queue.length && queue.head <= result) { result -= queue.dequeue(); } } console.log(result); }
2.
// Run by Node.js const readline = require('readline'); (async () => { let rl = readline.createInterface({ input: process.stdin }); const inputs = []; rl.on('line', (line) => inputs.push(line.trim())).on('close', () => { main(inputs); process.exit(); }); })(); function main(inputs) { const N = inputs[0]; let mapleStoryMap = Array.from({ length: N }, (_, idx) => inputs[idx + 1].split(' ').map(Number)) if (mapleStoryMap.flat().every(v => !v)) { console.log(0) return; } const Directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]; const check = (x, y) => x >= 0 && y >= 0 && x < N && y < N let result = 0; let 단풍이피지않았습니다_아직은가을이아니에오 = true; while (단풍이피지않았습니다_아직은가을이아니에오) { result += 1; const copyMap = JSON.parse(JSON.stringify(mapleStoryMap)); for (let x = 0; x < N; x += 1) { for (let y = 0; y < N; y += 1) { const now = mapleStoryMap[x][y]; if (now === 0) { for (let [dx, dy] of Directions) { const nx = x + dx; const ny = y + dy; if (check(nx, ny) && copyMap[nx][ny]) { copyMap[nx][ny] -= 1; } } } } } mapleStoryMap = copyMap; if (copyMap.flat().every(v => !v)) 단풍이피지않았습니다_아직은가을이아니에오 = false } console.log(result); }
- 구름과 상성이 맞지 않아서 fail. Infinity가 뜨는데… 식이 틀렸나…
// Run by Node.js const readline = require('readline'); (async () => { let rl = readline.createInterface({ input: process.stdin }); for await (const line of rl) { main(+line) rl.close(); } process.exit(); })(); function main(input) { const powNumber = input - 1 const result = Math.pow(5, powNumber) + Math.pow(4, powNumber) + 2 * Math.pow(3, powNumber) + Math.pow(2, powNumber) console.log(result % 100000007) }