Submission #217874

# Submission time Handle Problem Language Result Execution time Memory
217874 2020-03-31T06:57:12 Z KoalaMuch JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
6 ms 2688 KB
#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

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %s",&n,&k,s+1);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Incorrect 6 ms 2688 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Incorrect 6 ms 2688 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Incorrect 6 ms 2688 KB Output isn't correct
3 Halted 0 ms 0 KB -