티스토리 뷰

https://www.acmicpc.net/problem/10815

 

10815번: 숫자 카드

첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,

www.acmicpc.net

 

 

 

 

 

 

👩‍💻list만 사용한 코드 : 시간초과☠️

m = int(input())
mli = list(map(int, input().split()))
n = int(input())
nli = list(map(int, input().split()))
for i in nli:
  if i in set(mli):
    print(1, sep=' ', end=' ')
  else: 
    print(0, sep=' ', end=' ')

 

 

 

👩‍💻교집합 사용한 코드 : 성공🌈

m = int(input())
mset = list(map(int, input().split()))
n = int(input())
nset = list(map(int, input().split()))
section = set(mset) & set(nset)
for i in list(nset):
  if i in section:
    print(1, sep=' ', end=' ')
  else:
    print(0, sep=' ', end=' ')

 

 

🚀결과🚀

 

 

Point

교집합 구하는 방법
1. set1 & set2
2. set1.intersection(set2)
댓글
최근에 올라온 글
«   2025/04   »
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
Total
Today
Yesterday