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<vector>
#include<algorithm>
using namespace std;
vector<int> a,b,c;
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,k;
cin>>n>>k;
string s;
cin>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]=='J')
a.push_back(i);
if(s[i]=='O')
b.push_back(i);
if(s[i]=='I')
c.push_back(i);
}
int wynik=1000000000;
for(int i=0;i<a.size();i++)
{
int nas=i+k-1;
if(nas>=a.size())
break;
int gdzie1=lower_bound(b.begin(),b.end(),a[nas])-b.begin()+k-1;
if(gdzie1>=b.size())
continue;
// cout<<"zyje\n";
int gdzie2=lower_bound(c.begin(),c.end(),b[gdzie1])-c.begin()+k-1;
if(gdzie2>=c.size())
continue;
//cout<<"zyje2\n";
//cout<<a[i]<<" "<<a[nas]<<" "<<b[gdzie1]<<" "<<b[gdzie1-k+1]<<"\n";
wynik=min(wynik,c[gdzie2]-a[i]+1-3*k);
}
if(wynik==1000000000)
cout<<"-1";
else cout<<wynik;
return 0;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i=0;i<s.length();i++)
| ~^~~~~~~~~~~
ho_t2.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=0;i<a.size();i++)
| ~^~~~~~~~~
ho_t2.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(nas>=a.size())
| ~~~^~~~~~~~~~
ho_t2.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if(gdzie1>=b.size())
| ~~~~~~^~~~~~~~~~
ho_t2.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if(gdzie2>=c.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... |