Submission #1335804

#TimeUsernameProblemLanguageResultExecution timeMemory
1335804YSH2020JJOOII 2 (JOI20_ho_t2)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,t; cin >> n >> t;
	string s; cin >> s;
	//you want to trim the string so that it is as short as possible
	//we first find the positions of the joi
	vector<int> a;
	vector<int> b;
	vector<int> c ;
	for (int i = 0; i < n; i++) {
		if (s[i]=='J') a.push_back(i);
		else if (s[i]=='O') b.push_back(i);
		else c.push_back(i);
	}
	int ans = -1;
	if (b.size() < t || a.size() < t || c.size() < t) {cout << -1; return 0;}
	for (int i = 0; i <= (int)(b.size())-t; i++) {
		//you want to find the number of As before
		auto itr = lower_bound(a.begin(), a.end(), b[i])-a.begin();
		cout << itr;
		if (itr < t) continue;
		auto itr2 = lower_bound(c.begin(), c.end(), b[i+t-1])-c.begin();
		if (itr2+t-1 >= c.size()) continue;
		ans=max(ans,c[itr2+t-1]-a[itr-t]+1);
	}
	if (ans==-1) cout << -1;
	else cout << ans-t*3;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...