제출 #276807

#제출 시각아이디문제언어결과실행 시간메모리
276807islingrJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
6 ms768 KiB
#include <iostream>
using namespace std;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);

	int n, k, res = -1; string s; cin >> n >> k >> s;
	for (int l = 0, j = 0, o = 0, i = 0, cj = 0, co = 0, ci = 0; l < n; ++l) {
		while (j < n && cj < k) {
			if (s[j] == 'J') ++cj;
			if (s[j] == 'O') --co;
			++j;
		}
		while (o < n && co < k) {
			if (s[o] == 'O') ++co;
			if (s[o] == 'I') --ci;
			++o;
		}
		while (i < n && ci < k) if (s[i++] == 'I') ++ci;
		if (ci != k) break;
		if (res < 0) res = i - l - 3 * k;
		else res = min(res, i - l - 3 * k);
		if (s[l] == 'J') --cj;
	}
	cout << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...