Submission #209673

#TimeUsernameProblemLanguageResultExecution timeMemory
209673origami100JJOOII 2 (JOI20_ho_t2)C++11
13 / 100
2095 ms9988 KiB
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	set <int> J, O, I;
	for(int i = 0; i < n; i++){
		switch(s[i]){
			case 'J':
				J.insert(i);
				break;
			case 'O':
				O.insert(i);
				break;
			case 'I':
				I.insert(i);
				break;
		}
	}
	set <int>::iterator it1, it2, it3;
	it1 = J.begin();
	int mi = 200005;
	bool pos;
	for(int i = 0; i < J.size() - k + 1; i++){
		pos = true;
		it2 = it1;
		//cout << *it1 << ' ';
		for(int j = 0; j < k - 1 && pos; j++){
			it2++;
			if(it2 == J.end()){
				pos = false;
			}
		}
		if(pos == false) continue;
		//cout << *it2 << ' ';
		it2 = O.upper_bound(*it2);
		if(it2 == O.end()){
			continue;
		}
		//cout << *it2 << ' ';
		for(int j = 0; j < k - 1 && pos; j++){
			it2++;
			if(it2 == O.end()){
				pos = false;
			}
		}
		if(pos == false) continue;
		//cout << *it2 << ' ';
		it2 = I.upper_bound(*it2);
		if(it2 == I.end()){
			continue;
		}
		//cout << *it2 << ' ';
		for(int j = 0; j < k - 1 && pos; j++){
			it2++;
			if(it2 == I.end()){
				pos = false;
			}
		}
		if(pos == false) continue;
		//cout << *it2 << '\n';
		mi = min(mi, *it2 - *it1 + 1 - (k * 3));
		it1++;
	}
	if(mi == 200005) cout << -1;
	else cout << mi;
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:28:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < J.size() - k + 1; i++){
                 ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...