Submission #586196

#TimeUsernameProblemLanguageResultExecution timeMemory
586196hibikiJJOOII 2 (JOI20_ho_t2)C++11
100 / 100
6 ms2772 KiB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(x) (int)x.size()

int n, k;
int link[200005];
vector<int> idx[10];
char s[200005];

int get_ty(char x)
{
    if(x == 'J') return 1;
    if(x == 'O') return 2;
    if(x == 'I') return 3;
    exit(-1);
}

int main()
{
    scanf("%d %d",&n,&k);
    scanf("%s",s);
    for(int i = 0; i < n; i++)
    {
        int ty = get_ty(s[i]);
        link[i] = sz(idx[ty - 1]) - 1;
        idx[ty].pb(i);
    }
    int ans = 1e9;
    for(int bi = 0; bi < sz(idx[3]); bi++)
    {
        int fi = bi - k + 1;
        if(fi < 0) continue;
        int bo = link[idx[3][fi]];
        int fo = bo - k + 1;
        if(fo < 0) continue;
        int bj = link[idx[2][fo]];
        int fj = bj - k + 1;
        if(fj < 0) continue;
        ans = min(ans, idx[3][bi] - idx[1][fj] + 1 - 3 * k);
    }
    if(ans == 1e9) ans = -1;
    printf("%d\n",ans);
    return 0;
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%s",s);
      |     ~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...