반응형

전체 탐색으로 하면 시간 초과가 날 것 같아서 HashSet를 사용했다.

또한, 중복된 수가 없었기 때문에 HashSet 사용이 가능했다.


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
import java.io.FileInputStream;
import java.util.HashSet;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(new FileInputStream("input.txt"));
        // Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        HashSet<Integer> set = new HashSet<Integer>();
        for (int i = 0; i < N; i++) {
            set.add(sc.nextInt());
        }
 
        int M = sc.nextInt();
        for (int i = 0; i < M; i++) {
            if (set.contains(sc.nextInt())) {
                System.out.print(1);
            } else {
                System.out.print(0);
            }
            System.out.print(" ");
        }
    }
 
}
 
cs


반응형

+ Recent posts