# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870615 | Maite_Morale | JJOOII 2 (JOI20_ho_t2) | C++14 | 9 ms | 5604 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>
#define F first
#define S second
#define MAX 500005
#define oo 1e18
#define mod 1000000007
#define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
using namespace std;
typedef long long ll;
#define pll pair<ll , ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vpll vector<pll>
ll n,k;
string a;
map<char,ll> mp;
vll v[5];ll d[MAX];
int main(){
cin>>n>>k>>a;mp['J']=1;mp['O']=2;mp['I']=3;
for(int i=0;i<n;i++){
d[i]=v[mp[a[i]]].size();
v[mp[a[i]]].push_back(i);
}ll op=0,ip=0;ll ans=oo;
for(int i=0;i<=v[1].size()-k;i++){
op=max(op,v[1][i+k-1]+1);
while(op<n-1 && a[op]!='O')op++;
if(op==n || a[op]!='O')break;
if(d[op]+k-1>=v[2].size())break;
ip=max(ip,v[2][d[op]+k-1]+1);
while(ip<n-1 && a[ip]!='I')ip++;
if(ip==n || a[ip]!='I')break;
if(d[ip]+k-1>=v[3].size())break;
ans=min(ans,v[3][d[ip]+k-1]-v[1][i]+1-3*k);
}if(ans==oo)ans=-1;
cout<<ans;
return 0;
}
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... |