# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
219574 | MKopchev | JJOOII 2 (JOI20_ho_t2) | C++14 | 25 ms | 1908 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 nmax=2e5+42;
int n,k;
vector<int> seen[3];
int ask(int pos,int where)
{
if(where==3)return pos;
pos++;
int nxt_seen=lower_bound(seen[where].begin(),seen[where].end(),pos)-seen[where].begin();
if(nxt_seen+k-1<seen[where].size())return ask(seen[where][nxt_seen+k-1],where+1);
return 1e9;
}
int main()
{
scanf("%i%i",&n,&k);
for(int i=1;i<=n;i++)
{
char c=getchar();
while(c!='J'&&c!='O'&&c!='I')c=getchar();
if(c=='J')seen[0].push_back(i);
else if(c=='O')seen[1].push_back(i);
else seen[2].push_back(i);
}
int output=n+1;
for(auto start:seen[0])
output=min(output,ask(start-1,0)-start+1-3*k);
if(output>n)printf("-1\n");
else printf("%i\n",output);
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... |