• 문제 링크
https://www.acmicpc.net/problem/11419
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Map<Integer, Integer> map = new HashMap<>();
int n = read(), k = read();
while (n-- > 0) {
int c = read();
map.put(c, map.getOrDefault(c, 0) + 1);
}
bw.write(String.valueOf(find(map, k)));
bw.flush();
}
private static int find(Map<Integer, Integer> map, int k) {
for (int key : map.keySet()) if (map.get(key) % k != 0) return key;
return -1;
}
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' 카테고리의 다른 글
[백준] 25192 인사성 밝은 곰곰이 - Data Structure / Java (0) | 2025.04.06 |
---|---|
[백준] 33664 현실적인 생일 축하 방안 - Data Structure / Java (0) | 2025.04.04 |
[백준] 20732 Proofs - Data Structure / Java (0) | 2025.04.02 |
[백준] 20125 쿠키의 신체 측정 - Implementation / Java (0) | 2025.04.01 |
[백준] 1531 투명 - Implementation / Java (0) | 2025.03.31 |
댓글