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 <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
const int nmax=2e5;
int n, k;
string s;
vector <int> poz_j, poz_o, poz_i;
int main()
{
cin >> n >> k >> s;
for (int i=0;s[i];i++)
{
if (s[i]=='J')
{
poz_j.push_back (i);
}
else if (s[i]=='O')
{
poz_o.push_back (i);
}
else poz_i.push_back (i);
}
if (poz_j.size()<k || poz_i.size()<k || poz_o.size()<k)
{
cout << -1;
return 0;
}
bool found_sol=0;
int ret=nmax+5;
for (int i=k-1;i<poz_j.size();i++)
{
int rez_o=-1, st=0, dr=poz_o.size()-1;
while (st<=dr)
{
int mij = (st+dr) >> 1;
if (poz_o[mij]<=poz_j[i])
{
rez_o=mij;
st=mij+1;
}
else dr=mij-1;
}
rez_o+=k;
if (rez_o>poz_o.size()-1)
{
break;
}
int rez_i=-1;
st=0, dr=poz_i.size()-1;
while (st<=dr)
{
int mij = (st+dr) >> 1;
if (poz_i[mij]<=poz_o[rez_o])
{
rez_i=mij;
st=mij+1;
}
else dr=mij-1;
}
rez_i+=k;
if (rez_i>poz_i.size()-1)
{
break;
}
int rez_j=i-k+1;
found_sol=1;
ret=min (ret, poz_i[rez_i]-poz_j[rez_j]+1-3*k);
}
if (!found_sol)
{
cout << -1;
return 0;
}
cout << ret;
return 0;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:25:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | if (poz_j.size()<k || poz_i.size()<k || poz_o.size()<k)
| ~~~~~~~~~~~~^~
ho_t2.cpp:25:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | if (poz_j.size()<k || poz_i.size()<k || poz_o.size()<k)
| ~~~~~~~~~~~~^~
ho_t2.cpp:25:57: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | if (poz_j.size()<k || poz_i.size()<k || poz_o.size()<k)
| ~~~~~~~~~~~~^~
ho_t2.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i=k-1;i<poz_j.size();i++)
| ~^~~~~~~~~~~~~
ho_t2.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if (rez_o>poz_o.size()-1)
| ~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | if (rez_i>poz_i.size()-1)
| ~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |