# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
959797 | happy_node | JJOOII 2 (JOI20_ho_t2) | C++17 | 8 ms | 2268 KiB |
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;
const int MX=2e5+5;
int N,K;
string s;
vector<int> pos[3];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N>>K;
cin>>s;
for(int i=0;i<N;i++) {
if(s[i]=='J') pos[0].push_back(i);
if(s[i]=='O') pos[1].push_back(i);
if(s[i]=='I') pos[2].push_back(i);
}
int ans=2e9;
for(int i=0;i+K-1<pos[1].size();i++) {
int p=pos[1][i+K-1];
auto it=upper_bound(pos[2].begin(),pos[2].end(),p)-pos[2].begin();
if(it+K-1>=pos[2].size()) continue;
auto it2=lower_bound(pos[0].begin(),pos[0].end(),pos[1][i])-pos[0].begin();
if(it2==0) continue;
it2--;
if(it2-K+1<0) continue;
ans=min(ans,pos[2][it+K-1]-pos[0][it2-K+1]+1-3*K);
}
if(ans==2e9) {
cout<<-1<<'\n';
return 0;
}
cout<<ans<<'\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |