-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Silver IV] Title: 대칭 차집합, Time: 208 ms, Memory: 26112 KB -BaekjoonHub
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# [Silver IV] 대칭 차집합 - 1269 | ||
|
||
[문제 링크](https://www.acmicpc.net/problem/1269) | ||
|
||
### 성능 요약 | ||
|
||
메모리: 26112 KB, 시간: 208 ms | ||
|
||
### 분류 | ||
|
||
자료 구조, 해시를 사용한 집합과 맵, 트리를 사용한 집합과 맵 | ||
|
||
### 제출 일자 | ||
|
||
2023년 11월 13일 16:07:09 | ||
|
||
### 문제 설명 | ||
|
||
<p>자연수를 원소로 갖는 공집합이 아닌 두 집합 A와 B가 있다. 이때, 두 집합의 대칭 차집합의 원소의 개수를 출력하는 프로그램을 작성하시오. 두 집합 A와 B가 있을 때, (A-B)와 (B-A)의 합집합을 A와 B의 대칭 차집합이라고 한다.</p> | ||
<p> 예를 들어, A = { 1, 2, 4 } 이고, B = { 2, 3, 4, 5, 6 } 라고 할 때, A-B = { 1 } 이고, B-A = { 3, 5, 6 } 이므로, 대칭 차집합의 원소의 개수는 1 + 3 = 4개이다.</p> | ||
|
||
### 입력 | ||
|
||
<p>첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어진다. 각 집합의 원소의 개수는 200,000을 넘지 않으며, 모든 원소의 값은 100,000,000을 넘지 않는다.</p> | ||
|
||
### 출력 | ||
|
||
<p>첫째 줄에 대칭 차집합의 원소의 개수를 출력한다.</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
unordered_set<int> A, B; | ||
int main() { | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
|
||
int a, b; | ||
cin >> a >> b; | ||
for (int i = 0; i < a; i++) { | ||
int n; | ||
cin >> n; | ||
A.insert(n); | ||
} | ||
for (int j = 0; j < b; j++) { | ||
int n; | ||
cin >> n; | ||
B.insert(n); | ||
} | ||
A.merge(B); | ||
int c = B.size(); | ||
|
||
cout << a + b - 2 * c; | ||
} |