Skip to content

Commit a2c8b4e

Browse files
committed
[Silver IV] Title: 대칭 차집합, Time: 372 ms, Memory: 77044 KB -BaekjoonHub
1 parent 2b307d2 commit a2c8b4e

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# [Silver IV] 대칭 차집합 - 1269
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1269)
4+
5+
### 성능 요약
6+
7+
메모리: 77044 KB, 시간: 372 ms
8+
9+
### 분류
10+
11+
자료 구조, 집합과 맵, 해시를 사용한 집합과 맵, 트리를 사용한 집합과 맵
12+
13+
### 제출 일자
14+
15+
2026년 4월 27일 21:37:31
16+
17+
### 문제 설명
18+
19+
<p>자연수를 원소로 갖는 공집합이 아닌 두 집합 A와 B가 있다. 이때, 두 집합의 대칭 차집합의 원소의 개수를 출력하는 프로그램을 작성하시오. 두 집합 A와 B가 있을 때, (A-B)와 (B-A)의 합집합을 A와 B의 대칭 차집합이라고 한다.</p>
20+
<p> 예를 들어, A = { 1, 2, 4 } 이고, B = { 2, 3, 4, 5, 6 } 라고 할 때, A-B = { 1 } 이고, B-A = { 3, 5, 6 } 이므로, 대칭 차집합의 원소의 개수는 1 + 3 = 4개이다.</p>
21+
22+
### 입력
23+
24+
<p>첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어진다. 각 집합의 원소의 개수는 200,000을 넘지 않으며, 모든 원소의 값은 100,000,000을 넘지 않는다.</p>
25+
26+
### 출력
27+
28+
<p>첫째 줄에 대칭 차집합의 원소의 개수를 출력한다.</p>
29+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
3+
const { captureRejectionSymbol } = require("events");
4+
const fs = require("fs");
5+
6+
const input = fs
7+
.readFileSync(process.platform === "linux" ? "/dev/stdin" : "./input.txt")
8+
.toString()
9+
.trim()
10+
.split("\n");
11+
12+
const [A, B] = input[0].split(" ").map(Number);
13+
const setA = new Set(input[1].split(" ").map(Number));
14+
const setB = new Set(input[2].split(" ").map(Number));
15+
16+
/**
17+
* (A-B)와 (B-A)의 합집합: A와 B의 대칭 차집합
18+
* = A와 B 크기 더하고 교집합 크기 2배 빼면 됨
19+
*/
20+
21+
let size = 0;
22+
23+
//교집합 크기 구하기
24+
for (const a of setA) {
25+
if (setB.has(a)) {
26+
size++;
27+
}
28+
}
29+
30+
console.log(A + B - 2 * size);

0 commit comments

Comments
 (0)