[백준] 회전초밥

ERror.ASER·2021년 4월 12일
0

백준

목록 보기
49/69
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	static int N,d,k,c,isDuplicated,couponCheck,max; // N : 접시의 수, d : 초밥 가짓수, k : 연속해서 먹는 접시의 수, c : 쿠폰 번호
	static int[] sushi;
	static int[] isSelected;
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		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());
		sushi = new int[N];
		isSelected = new int[d+1];
		max = 0;
		
		for(int i=0; i<N; i++) {//벨트 위의 초밥들
			sushi[i] = Integer.parseInt(br.readLine());
		}
		
		for(int i=0; i<N; i++) {
			isDuplicated = 0;
			couponCheck = 1;
			
			for(int j=i; j<i+k; j++) {
				if(isSelected[sushi[j%N]]==1) isDuplicated++;
				else isSelected[sushi[j%N]]=1;
				
				if(sushi[j%N] == c) {
					couponCheck = 0;
					continue;
				}
			}
			max = Math.max(max, k-isDuplicated+couponCheck);
			isSelected = new int[d+1];
		}
		
		System.out.println(max);
	}
}
profile
지우의 블로그

0개의 댓글