# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872334 | Marco_Escandon | JJOOII 2 (JOI20_ho_t2) | C++11 | 12 ms | 4524 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;
typedef long long ll;
int main()
{
ll n,k;
cin>>n>>k;
string s;
cin>>s;
deque<ll> temp;
ll ac1[n+5]={ };
ll ac2[n+5]={ };
for(int i=0; i<n;i++)
ac1[i]=-1e9;
for(int i=0; i<n; i++)
{
if(s[i]=='J')
temp.push_back(i);
if(temp.size()==k)
{
ac1[i+1]=temp.front();
temp.pop_front();
}
if(i>0)
ac1[i]=max(ac1[i],ac1[i-1]);
ac2[i]=1e9;
}
temp.clear();
ac2[n]=1e9;
for(int i=n-1; i>-1; i--)
{
//ac2[i]=1e9;
if(s[i]=='I')
temp.push_back(i);
if(temp.size()==k)
{
if(i>0)
ac2[i-1]=temp.front();
temp.pop_front();
}
ac2[i]=min(ac2[i],ac2[i+1]);
//cout<<ac2[i]<<" ";
}
ll i=0; ll d=0;
ll c=0;
ll bs=1e9;
while(d!=n)
{
if(s[d]=='O')
c++;
while(c==k+1||(c==k&&s[i]!='O'))
{
if(s[i]=='O')
c--;
i++;
}
//cout<<c<<i<<" "<<d<<" "<<ac2[d]<<" "<<ac1[i]<<"\n";
if(c==k&&ac2[d]!=1e9&&ac1[i]!=-1e9)
{
bs=min(bs,ac2[d]+1-ac1[i]-(3*k));
}
d++;
}
if(bs>=n)
cout<<"-1";
else
cout<<bs;
}
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... |