# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
781517 | vjudge1 | JJOOII 2 (JOI20_ho_t2) | C++17 | 0 ms | 212 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;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define ll long long
#define pb push_back
#define N
int main(){
int n,k;cin>>n>>k;
string str;cin>>str;
int ans=1000000000;
for(int i=0;i<n;i++){
int j=0,o=0,I=0;
int cur=0;
int son,ner,de;
for(int jj=i;jj<n;jj++){
//cout<<i<<" "<<jj<<" "<<j<<" "<<o<<" "<<I<<" "<<cur<<" "<<str[jj]<<endl;
if(str[jj]=='J'){
if(j==k)continue;
if(j==0){
son=jj;
j++;
}
else{
cur+=jj-son-1;
son=jj;
j++;
}
}
if(str[jj]=='O'){
if(j!=k)continue;
if(o==k)continue;
if(o==0){
ner=jj;
cur+=ner-son-1;
o++;
}
else{
cur+=jj-ner-1;
ner=jj;
o++;
}
}
if(str[jj]=='I'){
if(j!=k||o!=k)continue;
if(I==0){
de=jj;
cur+=de-ner-1;I++;
}
else{
cur+=jj-de-1;
de=jj;
I++;
if(I==k){
ans=min(ans,cur);break;
}
}
}
}
}
if(ans==1000000000)ans=-1;
cout<<ans<<endl;
}
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... |