Skip to content

Commit 2420575

Browse files
authored
[20251027] BOJ / P5 / 버스 노선 / 한종욱
1 parent de7e0c6 commit 2420575

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
```
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static List<int[]> busLines;
9+
private static boolean[] contains;
10+
private static int N, M;
11+
public static void main(String[] args) throws IOException {
12+
init();
13+
sweep();
14+
15+
for (int i = 1; i <= M; i++) {
16+
if (!contains[i]) bw.write(i + " ");
17+
}
18+
bw.flush();
19+
bw.close();
20+
br.close();
21+
}
22+
23+
private static void init() throws IOException {
24+
N = Integer.parseInt(br.readLine());
25+
M = Integer.parseInt(br.readLine());
26+
27+
busLines = new ArrayList<>();
28+
contains = new boolean[M+1];
29+
30+
for (int i = 1; i <= M; i++) {
31+
StringTokenizer st = new StringTokenizer(br.readLine());
32+
int a = Integer.parseInt(st.nextToken());
33+
int b = Integer.parseInt(st.nextToken());
34+
35+
if (a < b) {
36+
busLines.add(new int[]{a, b, i});
37+
busLines.add(new int[]{a+N, b+N, i});
38+
} else {
39+
busLines.add(new int[]{a, b+N, i});
40+
}
41+
}
42+
43+
busLines.sort((o1, o2) -> {
44+
if (o1[0] == o2[0]) return Integer.compare(o2[1], o1[1]);
45+
return Integer.compare(o1[0], o2[0]);
46+
});
47+
}
48+
49+
private static void sweep() {
50+
int end = -1;
51+
52+
for (int[] busLine : busLines) {
53+
if (busLine[1] <= end) {
54+
contains[busLine[2]] = true;
55+
} else {
56+
end = busLine[1];
57+
}
58+
}
59+
}
60+
}
61+
```

0 commit comments

Comments
 (0)