-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathBOJ_15961.java
More file actions
57 lines (51 loc) · 1.68 KB
/
BOJ_15961.java
File metadata and controls
57 lines (51 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ_15961 {
static int N, c, k, d, arr[];
static int[] visit = new int[3001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = null;
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
d = Integer.parseInt(st.nextToken());
k = Integer.parseInt(st.nextToken());
c = Integer.parseInt(st.nextToken());
arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(br.readLine());
}
int cnt = 0;
int start = 0;
int end = k;
int answer = 1;
for (int i = 0; i < end; i++) {
if (visit[arr[i]] == 0) {
cnt++;
}
visit[arr[i]]++;
}
visit[c] += 1;
// 전에 C가 있었음 = cnt에 반영이 되어있음
answer = visit[c] > 1 ? cnt : ++cnt;
//System.out.println("0, 4 -> " + answer);
while (start <= N-1) {
if (--visit[arr[start]] == 0) {
cnt--;
}
end++;
if (visit[arr[(end - 1) % N]] == 0) {
cnt++;
}
visit[arr[(end - 1) % N]]++;
start++;
answer = Math.max(answer, cnt);
//System.out.println(start + ", " + end + " -> " + answer + "-" + cnt);
if (answer == k+1)
break;
}
System.out.println(answer);
}
}