Submission #244881

# Submission time Handle Problem Language Result Execution time Memory
244881 2020-07-05T08:22:24 Z maximath_1 JJOOII 2 (JOI20_ho_t2) C++11
0 / 100
5 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

int pref[200005][3], last[200005][3];
int n, k; string s;
int main(){
	cin >> n >> k >> s;
	for(int i = 0; i < n; i ++){
		for(int j = 0; j < 3; j ++)
			pref[i + 1][j] = pref[i][j];
		if(s[i] == 'J') pref[i + 1][0] ++;
		if(s[i] == 'O') pref[i + 1][1] ++;
		if(s[i] == 'I') pref[i + 1][2] ++;
	}

	int ans = 2e9, lf;
	lf = 0;
	for(int rg = 0; rg < n; rg ++){
		for(;pref[rg + 1][0] - pref[lf][0] >= k; lf ++);
		last[rg][0] = lf - 1;
	}
	lf = 0;
	for(int rg = 0; rg < n; rg ++){
		for(;pref[rg + 1][1] - pref[lf][1] >= k; lf ++);
		last[rg][1] = lf - 1;
	}
	lf = 0;
	for(int rg = 0; rg < n; rg ++){
		for(;pref[rg + 1][2] - pref[lf][2] >= k; lf ++);
		last[rg][2] = lf - 1;
	}
	for(int i = 0; i < n; i ++){
		int nw = last[i][2] - 1;
		if(nw >= 0) nw = last[nw][1] - 1;
		else nw = -3;
		if(nw >= 0) nw = last[nw][0] - 1;
		else nw = -3;

		if(nw != -3)
			ans = min(ans, i - nw);
	}

	if(ans == 2e9) cout << -1 << endl;
	else cout << ans - 3 * k << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Incorrect 5 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Incorrect 5 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Incorrect 5 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -