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;
vector<int> J, O, I;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k, ans=1e9;
cin >> n >> k;
for (int i=1; i<=n; i++)
{
char x;
cin >> x;
if (x=='J')
J.push_back(i);
else if (x=='O')
O.push_back(i);
else
I.push_back(i);
}
for (int i=0; i<=O.size()-k; i++)
{
int index=lower_bound(J.begin(), J.end(), O[i])-J.begin()-k;
int jndex=lower_bound(I.begin(), I.end(), O[i+k-1])-I.begin()+k-1;
if (index>=0 && jndex<I.size())
ans=min(ans, I[jndex]-J[index]+1-k*3);
}
if (ans==1e9)
cout << -1;
else
cout << ans;
return 0;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:22:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i=0; i<=O.size()-k; i++)
| ~^~~~~~~~~~~~
ho_t2.cpp:26:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if (index>=0 && jndex<I.size())
| ~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |