답안 #233711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233711 2020-05-21T13:25:10 Z duality JJOOII 2 (JOI20_ho_t2) C++11
0 / 100
4 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

char S[200000];
int pre[3][200001],n[3][200001];
int main() {
    int i,j;
    int N,K;
    scanf("%d %d",&N,&K);
    for (i = 0; i < N; i++) {
        scanf(" %c",&S[i]);
        for (j = 0; j < 3; j++) pre[j][i+1] = pre[j][i];
        if (S[i] == 'J') pre[0][i+1]++;
        else if (S[i] == 'O') pre[1][i+1]++;
        else pre[2][i+1]++;
    }

    int ans = 1e9;
    j = 0;
    for (i = 0; i < N; i++) {
        while (pre[0][i+1]-pre[0][j] >= K) j++;
        n[0][i] = j-1;
    }
    j = 0;
    for (i = 0; i < N; i++) {
        while (pre[1][i+1]-pre[1][j] >= K) j++;
        n[1][i] = j-1;
    }
    for (i = 0; i < N; i++) {
        while (pre[2][i+1]-pre[2][j] >= K) j++;
        n[2][i] = j-1;
    }
    for (i = 0; i < N; i++) {
        int u = n[2][i]-1;
        if (u >= 0) u = n[1][u]-1;
        if (u >= 0) u = n[0][u]-1;
        if (u != -2) ans = min(ans,i-u);
    }
    if (ans == 1e9) printf("-1\n");
    else printf("%d\n",ans-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",&N,&K);
     ~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c",&S[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -