Skip to content

Commit 1764ffb

Browse files
authored
[20250617] BOJ / P5 / 상남자 곽철용 / 권혁준
1 parent da9b4ba commit 1764ffb

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
```java
2+
import java.math.BigInteger;
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class IOController {
7+
BufferedReader br;
8+
BufferedWriter bw;
9+
StringTokenizer st;
10+
11+
public IOController() {
12+
br = new BufferedReader(new InputStreamReader(System.in));
13+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
14+
st = new StringTokenizer("");
15+
}
16+
17+
String nextLine() throws Exception {
18+
String line = br.readLine();
19+
st = new StringTokenizer(line);
20+
return line;
21+
}
22+
23+
String nextToken() throws Exception {
24+
while (!st.hasMoreTokens()) nextLine();
25+
return st.nextToken();
26+
}
27+
28+
int nextInt() throws Exception {
29+
return Integer.parseInt(nextToken());
30+
}
31+
32+
long nextLong() throws Exception {
33+
return Long.parseLong(nextToken());
34+
}
35+
36+
double nextDouble() throws Exception {
37+
return Double.parseDouble(nextToken());
38+
}
39+
40+
void close() throws Exception {
41+
bw.flush();
42+
bw.close();
43+
}
44+
45+
void write(String content) throws Exception {
46+
bw.write(content);
47+
}
48+
49+
}
50+
51+
public class Main {
52+
53+
static IOController io;
54+
55+
//
56+
57+
static int N, M, K, base;
58+
static List<Integer> A;
59+
60+
public static void main(String[] args) throws Exception {
61+
62+
io = new IOController();
63+
64+
init();
65+
solve();
66+
67+
io.close();
68+
69+
}
70+
71+
public static void init() throws Exception {
72+
73+
N = io.nextInt();
74+
M = io.nextInt();
75+
K = io.nextInt();
76+
77+
boolean[] ex = new boolean[4*N+1];
78+
for(int i=0;i<M;i++) {
79+
ex[io.nextInt()] = true;
80+
ex[io.nextInt()] = true;
81+
}
82+
83+
int a = io.nextInt(), b = io.nextInt();
84+
ex[a] = true;
85+
ex[b] = true;
86+
base = Math.abs((a%K) - (b%K));
87+
88+
A = new ArrayList<>();
89+
for(int i=1;i<=4*N;i++) if(!ex[i]) A.add(i%K);
90+
91+
}
92+
93+
static void solve() throws Exception {
94+
95+
Collections.sort(A);
96+
int e = A.size() - 1, s = A.size()/2, ans = 0;
97+
while(s >= 0) {
98+
int a = A.get(e), b = A.get(s);
99+
if(a-b > base) {
100+
e--;
101+
ans++;
102+
}
103+
s--;
104+
}
105+
io.write(Math.min(ans, M-1) + "\n");
106+
107+
108+
}
109+
110+
}
111+
```

0 commit comments

Comments
 (0)