• 문제 링크
https://www.acmicpc.net/problem/16960
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int[][] mat = new int[read()][];
int m = read();
for (int i = 0; i < mat.length; i++) {
int[] arr = new int[read()];
for (int j = 0; j < arr.length; j++) arr[j] = read();
mat[i] = arr;
}
int[] cnt = new int[m + 1];
for (int[] arr : mat) for (int i : arr) cnt[i]++;
bw.write(isPossible(mat, cnt) ? "1" : "0");
bw.flush();
}
private static boolean isPossible(int[][] mat, int[] cnt) {
for (int[] arr : mat) {
boolean flag = true;
for (int i : arr) if (--cnt[i] == 0) flag = false;
if (flag) return true;
for (int i : arr) cnt[i]++;
}
return false;
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 16955 오목, 이길 수 있을까? - Brute Force / Java (0) | 2025.07.23 |
---|---|
[백준] 22282 H-Index - Brute Force / Java (0) | 2025.07.22 |
[백준] 9182 Biorhythms - Brute Force / Java (0) | 2025.07.20 |
[백준] 30306 Better Dice - Brute Force / Java (0) | 2025.07.19 |
[백준] 33691 Arkain 대시보드 - Data Structure / Java (0) | 2025.07.18 |
댓글