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>
#define ll long long
#define pii pair<int,int>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
string s;
cin>>n>>k>>s;
vector<int> J, O, I;
for(int i=0;i<n;i++) {
if(s[i]=='J') J.push_back(i);
else if(s[i]=='O') O.push_back(i);
else I.push_back(i);
}
int sz = INT_MAX;
for(int j=k-1;j<J.size();j++) {
int o = upper_bound(O.begin(), O.end(), J[j])-O.begin();
if(o+k-1>=O.size()) continue;
o += k-1;
int i = upper_bound(I.begin(), I.end(), O[o])-I.begin();
if(i+k-1>=I.size()) continue;
i += k-1;
sz = min(sz, I[i]-J[j-k+1]+1);
}
if(sz==INT_MAX) {
printf("-1");
return 0;
}
printf("%d", sz-k*3);
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int j=k-1;j<J.size();j++) {
| ~^~~~~~~~~
ho_t2.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if(o+k-1>=O.size()) continue;
| ~~~~~^~~~~~~~~~
ho_t2.cpp:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if(i+k-1>=I.size()) continue;
| ~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |