Submission #209385

#TimeUsernameProblemLanguageResultExecution timeMemory
209385zhacatomnJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
5 ms376 KiB
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]){
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int res = -1;
	deque <int> J, O, I;
	for(int i = 0; i < n; i++){
		char c = s[i];
		if(c == 'J'){
			J.push_front(i);
			if(J.size() >= k){
				if(O.empty())
					O.push_front(J.back());
				else{
					O[0] = max(O[0], J.back());
				}
				J.pop_back();
			}
		}
		else if(c == 'O'){
			O.push_front(-1);
			if(O.size() >= k + 1){
				if(I.empty())
					I.push_front(O.back());
				else{
					I[0] = max(I[0], O.back());
				}
				O.pop_back();
			}
		}
		else{
			I.push_front(-1);
			if(I.size() >= k + 1){
				int temp = I.back();
				temp = i - temp + 1 - 3 * k;
				if(temp != -1){
					res = res == -1 ? temp : min(res, temp);
				}
				I.pop_back();
			}
		}
		/*
		for(auto it: J)
			cout << it << " ";
		cout << "\n";
		for(auto it: O)
			cout << it << " ";
		cout << "\n";
		for(auto it: I)
			cout << it << " ";
		cout << "\n";
		*/
	}
	cout << res;
	return 0;
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main(int, const char**)':
ho_t2.cpp:15:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(J.size() >= k){
       ~~~~~~~~~^~~~
ho_t2.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(O.size() >= k + 1){
       ~~~~~~~~~^~~~~~~~
ho_t2.cpp:37:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(I.size() >= k + 1){
       ~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...