Submission #393599

# Submission time Handle Problem Language Result Execution time Memory
393599 2021-04-24T05:18:21 Z 79brue JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
198 ms 47648 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k;
char s[200005];
int ans = INT_MAX;

int sparse[200005][20][3];

void makeSparse(){
    int recent[3] = {n+1, n+1, n+1};
    sparse[n+1][0][0] = sparse[n+1][0][1] = sparse[n+1][0][2] = n+1;
    for(int i=n; i>=0; i--){
        for(int j=0; j<3; j++) sparse[i][0][j] = recent[j];
        if(s[i] == 'J') recent[0] = i;
        else if(s[i] == 'O') recent[1] = i;
        else recent[2] = i;
    }

    for(int d=1; d<20; d++){
        for(int i=0; i<=n+1; i++){
            for(int j=0; j<3; j++){
                sparse[i][d][j] = sparse[sparse[i][d-1][j]][d-1][j];
            }
        }
    }
}

int kth(int x, int len, int y){
    for(int d=0; d<20; d++){
        if((len>>d) & 1) x = sparse[x][d][y];
    }
    return x;
}

int main(){
    scanf("%d %d %s", &n, &k, s+1);
    makeSparse();

    for(int i=1; i<=n; i++){
        int tmp = i-1;
        tmp = kth(tmp, k, 0);
        tmp = kth(tmp, k, 1);
        tmp = kth(tmp, k, 2);
        if(tmp != n+1) ans = min(ans, (n-3*k) - (n-tmp) - (i-1));
    }
    printf("%d\n", ans == INT_MAX ? -1 : ans);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |     scanf("%d %d %s", &n, &k, s+1);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 2 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 2 ms 716 KB Output is correct
19 Correct 2 ms 972 KB Output is correct
20 Correct 2 ms 972 KB Output is correct
21 Correct 2 ms 972 KB Output is correct
22 Correct 1 ms 844 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 972 KB Output is correct
25 Correct 1 ms 972 KB Output is correct
26 Correct 1 ms 972 KB Output is correct
27 Correct 1 ms 972 KB Output is correct
28 Correct 2 ms 948 KB Output is correct
29 Correct 1 ms 940 KB Output is correct
30 Correct 1 ms 972 KB Output is correct
31 Correct 1 ms 560 KB Output is correct
32 Correct 1 ms 940 KB Output is correct
33 Correct 2 ms 940 KB Output is correct
34 Correct 1 ms 972 KB Output is correct
35 Correct 2 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 2 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 2 ms 716 KB Output is correct
19 Correct 2 ms 972 KB Output is correct
20 Correct 2 ms 972 KB Output is correct
21 Correct 2 ms 972 KB Output is correct
22 Correct 1 ms 844 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 972 KB Output is correct
25 Correct 1 ms 972 KB Output is correct
26 Correct 1 ms 972 KB Output is correct
27 Correct 1 ms 972 KB Output is correct
28 Correct 2 ms 948 KB Output is correct
29 Correct 1 ms 940 KB Output is correct
30 Correct 1 ms 972 KB Output is correct
31 Correct 1 ms 560 KB Output is correct
32 Correct 1 ms 940 KB Output is correct
33 Correct 2 ms 940 KB Output is correct
34 Correct 1 ms 972 KB Output is correct
35 Correct 2 ms 940 KB Output is correct
36 Correct 131 ms 44264 KB Output is correct
37 Correct 140 ms 47556 KB Output is correct
38 Correct 138 ms 47628 KB Output is correct
39 Correct 195 ms 47164 KB Output is correct
40 Correct 182 ms 47616 KB Output is correct
41 Correct 176 ms 47564 KB Output is correct
42 Correct 176 ms 47632 KB Output is correct
43 Correct 118 ms 29764 KB Output is correct
44 Correct 130 ms 36940 KB Output is correct
45 Correct 188 ms 47648 KB Output is correct
46 Correct 198 ms 47564 KB Output is correct
47 Correct 187 ms 47632 KB Output is correct
48 Correct 188 ms 47628 KB Output is correct
49 Correct 119 ms 31776 KB Output is correct
50 Correct 179 ms 47556 KB Output is correct
51 Correct 194 ms 47636 KB Output is correct
52 Correct 164 ms 45772 KB Output is correct
53 Correct 180 ms 47556 KB Output is correct
54 Correct 106 ms 47564 KB Output is correct
55 Correct 130 ms 47632 KB Output is correct
56 Correct 133 ms 47632 KB Output is correct