문제접근![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
•
겹치는 녀석 체크
•
쿠폰을 사용할 수 있는지 체크
•
k만큼에서 겹치는 녀석을 빼고 쿠폰을 사용할 수 있으면 더한다
놓쳤던 부분![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
•
인덱스를 잘못 생각하여 벡터 resize를 부족하게 해줌
코드![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
2252 KB
420 ms
#include <iostream>
#include <vector>
#include <algorithm>
int n, d, k, c;
std::vector<int> sushi;
std::vector<int> check_sushi;
void input_setting()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
}
void input()
{
std::cin >> n >> d >> k >> c;
sushi.resize(n);
check_sushi.resize(d + 1);
for (int i = 0; i < n; i++)
std::cin >> sushi[i];
}
void solution()
{
int start = 0, check;
int flag;
int answer = 0;
int overlap;
while (start < n)
{
std::fill(check_sushi.begin(), check_sushi.end(), 0);
check = start;
flag = 1;
overlap = 0;
while (check < start + k)
{
if (sushi[check % n] == c)
flag = 0;
if (check_sushi[sushi[check % n]] == 1)
++overlap;
else
check_sushi[sushi[check % n]] = 1;
++check;
}
++start;
answer = std::max(answer, k - overlap + flag);
}
std::cout << answer;
}
int main(void)
{
input_setting();
input();
solution();
return (0);
}
C++
복사