# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
217874 | KoalaMuch | JJOOII 2 (JOI20_ho_t2) | C++14 | 6 ms | 2688 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 N = 2e5+5;
int dp[N][3];
char s[N];
int get(char c)
{
if(c=='J') return 0;
else if(c=='O') return 1;
return 2;
}
int main()
{
int n,k;
scanf("%d %d %s",&n,&k,s+1);
memset(dp,127,sizeof dp);
for(int i=n-1;i>=0;i--)
{
dp[i][get(s[i+1])] = i+1;
for(int j=0;j<3;j++) dp[i][j] = min(dp[i][j],dp[i+1][j]);
}
int cur = 0,st = 1e9,en = 0;
for(int i=0;i<3;i++)
{
for(int j=1;j<=k;j++)
{
if(cur>n) return !puts("-1");
cur = dp[cur][i];
st = min(st,cur),en = max(en,cur);
}
}
printf("%d\n",en-st+1-3*k);
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... |