Submission #256932

# Submission time Handle Problem Language Result Execution time Memory
256932 2020-08-03T12:09:33 Z akat JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
1 ms 384 KB
#include<bits/stdc++.h>
using namespace std;
string s;
int k;
deque<int> d[3];
char c[3] = {'J', 'O', 'I'};
void rem(int x)
{
	while((int)d[x].size() > k)
		d[x].pop_front();
}
void update(int x, int y)
{
	rem(x);
	for(int l = d[y].back() + 1; l < d[x].front(); l++)
		if(s[l] == c[y]) d[y].push_back(l);
	d[y].pop_back();
	d[y].push_back(d[x].front() - 1);
}
void add_letter(int x)
{
	int l;
	for(l = 0; l < 2; l++)
	{
		if((int)d[l].size() < k)
		{
			if(s[x] == c[l]) d[l].push_back(x);
			return;
		}
	}
	if(s[x] != c[2]) return;
	if((int)d[2].size() < k)
	{
		d[2].push_back(x);
		return;
	}
	update(2,1);
	update(1,0);
	rem(0);
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, l, ans = -1;
	cin>>n>>k>>s;
	for(l = 0; l < n; l++)
	{
		add_letter(l);
		if((int)d[2].size() == k)
		{
			int cans = d[2].back() - d[0].front() + 1 - k * 3;
			if(ans == -1 || ans > cans) ans = cans;
		}
	}
	cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -