Submission #209385

# Submission time Handle Problem Language Result Execution time Memory
209385 2020-03-14T03:49:13 Z zhacatomn JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
5 ms 376 KB
#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

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 time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 364 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Incorrect 5 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 364 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Incorrect 5 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 364 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Incorrect 5 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -