This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
vector <int> J, O, I;
for(int i = 0; i < n; i++){
switch(s[i]){
case 'J':
J.push_back(i);
break;
case 'O':
O.push_back(i);
break;
case 'I':
I.push_back(i);
break;
}
}
vector <int>::iterator it1, it2, it3;
it1 = J.begin();
int mi = 200005;
bool pos;
for(int i = 0; i < J.size() - k + 1; i++){
it2 = it1;
//cout << *it1 << ' ';
if(J.end() - k + 1 <= it2) continue;
it2 = it2 + k - 1;
//cout << *it2 << ' ';
it2 = upper_bound(O.begin(), O.end(), *it2);
//cout << *it2 << ' ';
if(O.end() - k + 1 <= it2) continue;
it2 = it2 + k - 1;
//cout << *it2 << ' ';
it2 = upper_bound(I.begin(), I.end(), *it2);
//cout << *it2 << ' ';
if(I.end() - k + 1 <= it2) continue;
it2 = it2 + k - 1;
//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++){
~~^~~~~~~~~~~~~~~~~~
ho_t2.cpp:27:7: warning: unused variable 'pos' [-Wunused-variable]
bool pos;
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |