Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions 3주차/강의실 배정/SolutionByIS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

let N = 0; // 강의 개수
let tables = [];

rl.on('line', (line) => {
if (N === 0) {
N = Number(line);
} else {
const [S, F] = line.split(' ').map(Number);
tables.push([S, F]);
}
}).on('close', () => {
// 끝나는 순서대로 정렬
tables.sort((a, b) => a[1] - b[1]);

let ansCnt = 1;
let now = tables[0][1];

for (let i = 1; i < N; i++) {
if (tables[i][0] >= now) {
now = tables[i][1];
ansCnt++;
}
}

console.log(ansCnt);
});
21 changes: 21 additions & 0 deletions 3주차/수퍼바이러스/SolutionByIS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

const inputLines = [];

rl.on('line', (line)=> {
inputLines.push(line.split(" ").map(BigInt));
}).on('close', () => {
let [K, P, N] = inputLines[0];
N *= 10n; // 0.1초마다 증가

let ans = K;
for (let i = 0; i < Number(N); i++) {
ans = (ans * P) % BigInt(1000000007);
}

console.log(Number(ans));
});
60 changes: 60 additions & 0 deletions 3주차/출퇴근길/SolutionByIS(실패).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

let n = 0, m = 0; // n: 정점 개수, m: 간선 개수
let S = 0, T = 0; // S: 집, T: 회사
let curLine = 0;
let graph = new Map(); // 인접 리스트

function findNodes(start) {
const visited = new Set();
const endNode = (start === S ? T : S);

function dfs(node) {
visited.add(node);

for (let next of graph.get(node)) {
if (next === endNode)
continue;

if(!visited.has(next)) {
dfs(next);
}
}
}

dfs(start);
return visited;
}

rl.on('line', (line) => {
if (n === 0) {
[n, m] = line.split(' ').map(Number);
// 인접 리스트 초기화(n까지)
for (let i = 0; i <= n; i++) {
graph.set(i, []);
}
} else if (curLine < m) {
const [x, y] = line.split(' ').map(Number);
graph.get(x).push(y);
curLine++;
} else {
[S, T] = line.split(' ').map(Number);
}
}).on('close', () => {
const nodesFromS = findNodes(S);
const nodesFromT = findNodes(T);

// 출퇴근길 노드 중에서 교집합 필터링
const ansNodes = new Set(
[...nodesFromS].filter(n => nodesFromT.has(n))
);

console.log(ansNodes.size);
});

// 5, 15, 22, 25번 케이스 오답
// 31~39 케이스 런타임 에러