• 문제 링크
https://www.acmicpc.net/problem/10471
• 풀이 코드
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));
StringBuilder sb = new StringBuilder();
boolean[] visit = new boolean[read() + 1];
int[] arr = new int[read() + 2];
arr[arr.length - 1] = visit.length - 1;
for (int i = 1; i < arr.length - 1; i++) arr[i] = read();
for (int i = 0; i < arr.length; i++) for (int j = i + 1; j < arr.length; j++) visit[arr[j] - arr[i]] = true;
for (int i = 0; i < visit.length; i++) if (visit[i]) sb.append(i).append(' ');
bw.write(sb.toString());
bw.flush();
}
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' 카테고리의 다른 글
[백준] 32290 MEX vs OR - Brute Force / Java (0) | 2025.03.06 |
---|---|
[백준] 10372 Alarm Clock - Brute Force / Java (0) | 2025.03.05 |
[백준] 24077 比較 (Comparison) - Brute Force / Java (0) | 2025.03.03 |
[백준] 32942 그래프와 그래프 - Graph Theory / Java (0) | 2025.03.02 |
[백준] 24789 Railroad - Graph Theory / Java (0) | 2025.03.01 |
댓글