[λ°±μ€] 1269 λμΉ μ°¨μ§ν© with Python
π BOJ 1269 λμΉ μ°¨μ§ν©
π‘ 쑰건
μμ°μλ₯Ό μμλ‘ κ°λ 곡μ§ν©μ΄ μλ λ μ§ν© Aμ Bκ° μλ€.
λ μ§ν© Aμ Bκ° μμ λ, (A-B)μ (B-A)μ ν©μ§ν©μ Aμ Bμ λμΉ μ°¨μ§ν©μ΄λΌκ³ νλ€.
μλ₯Ό λ€μ΄, A = { 1, 2, 4 } μ΄κ³ , B = { 2, 3, 4, 5, 6 } λΌκ³ ν λ,
A-B = { 1 } μ΄κ³ , B-A = { 3, 5, 6 } μ΄λ―λ‘,
λμΉ μ°¨μ§ν©μ μμμ κ°μλ 1 + 3 = 4κ°μ΄λ€.κ° μ§ν©μ μμμ κ°μλ 200,000μ λμ§ μμΌλ©°, λͺ¨λ μμμ κ°μ 100,000,000μ λμ§ μλλ€.
λμΉ μ°¨μ§ν©μ μμμ κ°μλ₯Ό μΆλ ₯νλ λ¬Έμ
ν΄μλ§΅, μλ£κ΅¬μ‘° μ νμ λ¬Έμ
π₯ μμ€ μ½λ
from sys import stdin
n, m = map(int, stdin.readline().split())
a = set(map(int, stdin.readline().split()))
b = set(map(int, stdin.readline().split()))
print(len(a - b) + len(b - a))
π μμ λ° μ€νκ²°κ³Ό
μμ
3 5
1 2 4
2 3 4 5 6
μ€νκ²°κ³Ό
4
β¨οΈ λ¬Έμ νμ΄
μ§ν© Aμ μμμ κ°μμ μ§ν© Bμ μμμ κ°μλ₯Ό μ λ ₯ λ°λλ€.
κ° μ§ν©μ μμλ₯Ό set()μΌλ‘ μ λ ₯λ°μ μ μ₯νλ€.
(a - b) μ κΈΈμ΄μ (b - a)μ κΈΈμ΄λ₯Ό λν λ€ μΆλ ₯νλ€.