• students 배열을 map과 같이 활용
  • 학생의 비어 있지 않은 시간에 과목의 수업 시간이 존재하면 해당 과목은 학생이 들을 수 없다
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.io.*;
import java.util.*;

public class Main {
	static int N, M;
	static int[][] subjects = new int[1001][];
	static boolean[][] students = new boolean[10001][51];

	static void solution() {
		for (int i = 0; i < M; i++) {
			int cnt = 0;
			for (int j = 0; j < N; j++) {
				int NN = subjects[j].length;
				boolean pass = true;
				for (int k = 0; k < NN; k++) {
					int time = subjects[j][k];
					// 과목 수업 시간에 학생이 비는 시간이 아니면
					if (!students[i][time]) {
						pass = false;
						break;
					}
				}
				if (pass) cnt++;
			}
			System.out.println(cnt);
		}
	}

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(in.readLine());
		for (int i = 0; i < N; i++) {
			StringTokenizer st = new StringTokenizer(in.readLine(), " ");
			int NN = Integer.parseInt(st.nextToken());
			// 과목의 수업 시간 저장
			subjects[i] = new int[NN];
			for (int j = 0; j < NN; j++)
				subjects[i][j] = Integer.parseInt(st.nextToken());
		}
		M = Integer.parseInt(in.readLine());
		for (int i = 0; i < M; i++) {
			StringTokenizer st = new StringTokenizer(in.readLine(), " ");
			int MM = Integer.parseInt(st.nextToken());
			// 학생의 비는 시간 저장
			for (int j = 0; j < MM; j++) {
				int time = Integer.parseInt(st.nextToken());
				students[i][time] = true;
			}
		}
		solution();
	}
}