알고리즘/백준
2531_회전 초밥
베리영young
2025. 4. 26. 23:15
사용 알고리즘: 완전 탐색
사용 언어: java
package ssafyRoom2_Monthly_Silver_Random_Defense;
import java.util.*;
public class Main_bj_2531_회전초밥 {
static int N, d, k, c, answer = 1, com[];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt(); //접시 개수
d = sc.nextInt(); //초밥 가짓수
k = sc.nextInt(); //연속해서 먹는 접시 수
c = sc.nextInt(); //쿠폰 번호(공짜로 먹을 수 있는 초밥)
com = new int[N*2];
for (int i = 0; i < N; i++) {
int a = sc.nextInt();
com[i] = a;
com[i+N] = a;
}
for(int start=0; start<N; start++) {
boolean[] eat = new boolean[d+1];
eat[c] = true;
for (int i = start; i < start+k; i++) {
eat[com[i]] = true;
}
int cnt = 0;
for(boolean e : eat) {
if(e) cnt++;
}
answer = Math.max(answer, cnt);
}
System.out.println(answer);
}
}
그냥 딱 하면 된다.
시간을 줄이려다가 오히려 시간 초과가 났다.