티스토리 뷰
https://www.acmicpc.net/problem/1269
1269번: 대칭 차집합
첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어
www.acmicpc.net
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split("\n").map(v => v.split(' ').map(Number))
const [N, M] = input.shift();
const A = input.shift().sort((a, b) => a - b);
const B = input.shift().sort((a, b) => a - b);
let answer = A.length + B.length;
A.forEach(a => {
let min = 0;
let max = B.length - 1;
let find = false;
while (min <= max) {
let mid = Math.floor((max + min) / 2);
if (B[mid] == a) {
find = true;
break;
} else if (B[mid] > a) {
max = mid - 1;
} else {
min = mid + 1;
}
}
if (find) answer--;
})
B.forEach(b => {
let min = 0;
let max = A.length - 1;
let find = false;
while (min <= max) {
let mid = Math.floor((max + min) / 2);
if (A[mid] == b) {
find = true;
break;
} else if (A[mid] > b) {
max = mid - 1;
} else {
min = mid + 1;
}
}
if (find) answer--;
})
console.log(answer)
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 14627번: 파닭파닭 (0) | 2022.04.22 |
---|---|
Node.js) 백준 16434번 드래곤 앤 던전 (0) | 2022.04.21 |
Node.js) 백준 7795번: 먹을 것인가 먹힐 것인가 (0) | 2022.04.20 |
Node.js) 백준 6236번: 용돈 관리 (0) | 2022.04.20 |
Node.js)백준 2343번: 기타 레슨 (0) | 2022.04.19 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 서버개발
- MOD
- 면접질문
- KMP
- 다이나밍프로그래밍
- 최소공통조상
- DB 생성
- 은둔청년체험
- BFS
- create databases;
- 로드나인
- create db
- 다이나믹프로그래밍
- node.js
- MySQL
- 투포인터
- 투포인터 연습
- 그래프
- 롱베케이션
- 서버점검
- 개발자면접
- 동적프로그래밍
- 면접비
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함