반응형
문제
https://www.acmicpc.net/problem/2531
JAVA코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
private static int N, d, k, c;
private static List<Integer> list = new ArrayList<>();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer 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());
HashSet<Integer> cnt = new HashSet<>();
for (int idx = 0; idx < N; idx++) {
list.add(Integer.parseInt(br.readLine()));
}
int max = 0;
int start = 0;
int end = k;
while (start < N) {
cnt.clear();
cnt.add(c);
if (end < start) {
for (int idx = 0; idx < end; idx++) {
cnt.add(list.get(idx));
}
for (int idx = start; idx < N; idx++) {
cnt.add(list.get(idx));
}
} else {
for (int idx = start; idx < end; idx++) {
cnt.add(list.get(idx));
}
}
max = Math.max(max, cnt.size());
start++;
if (end == N)
end = 1;
else
end++;
}
br.close();
System.out.println(max);
}
}
반응형
'Algorithm > 문제 풀이' 카테고리의 다른 글
[BAEKJOON_1316 - JAVA] 그룹 단어 체커 (0) | 2023.07.10 |
---|---|
[BAEKJOON_21610 - JAVA] 마법사 상어와 비바라기 (0) | 2023.06.29 |
[BAEKJOON_19637 - JAVA] IF문 좀 대신 써줘 (0) | 2023.06.17 |
[BAEKJOON_1446 - JAVA] 지름길 (0) | 2023.06.16 |
[BAEKJOON_14503 -JAVA] 로봇 청소기 (0) | 2023.06.16 |