Submission #201734

# Submission time Handle Problem Language Result Execution time Memory
201734 2020-02-11T21:04:31 Z silxikys JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
58 ms 43016 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 2e5+5, maxk = 18;
int n, K;
string s;

int jJ[maxk][maxn], jO[maxk][maxn], jI[maxk][maxn];

int walk(int i, int ar[][maxn]) {
    for (int k = maxk-1; k >= 0; k--) {
        if (K & (1<<k)) {
            i = ar[k][i];
        }
        if (i == -1) return -1;
    }
    return i;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> K >> s;
    memset(jJ,-1,sizeof jJ);
    memset(jO,-1,sizeof jO);
    memset(jI,-1,sizeof jI);
    for (int i = n-1; i >= 0; i--) {
        jJ[0][i] = s[i] == 'J' ? i+1 : jJ[0][i+1];
        for (int k = 1; k < maxk; k++) {
            jJ[k][i] = jJ[k-1][i] == -1 ? -1 : jJ[k-1][jJ[k-1][i]];
        }
    }
    for (int i = n-1; i >= 0; i--) {
        jO[0][i] = s[i] == 'O' ? i+1 : jO[0][i+1];
        for (int k = 1; k < maxk; k++) {
            jO[k][i] = jO[k-1][i] == -1 ? -1 : jO[k-1][jO[k-1][i]];
        }
    }
    for (int i = n-1; i >= 0; i--) {
        jI[0][i] = s[i] == 'I' ? i+1 : jI[0][i+1];
        for (int k = 1; k < maxk; k++) {
            jI[k][i] = jI[k-1][i] == -1 ? -1 : jI[k-1][jI[k-1][i]];
        }
    }

    int ans = 2e9;
    for (int i = 0; i < n; i++) {
        int r = i;
        r = walk(r,jJ);
        if (r == -1) continue;
        r = walk(r,jO);
        if (r == -1) continue;
        r = walk(r,jI);
        if (r == -1) continue;
        int tr = (r-i)-3*K;
        ans = min(ans,tr);
    }
    cout << (ans < 2e9 ? ans : -1) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 42616 KB Output is correct
2 Correct 26 ms 42616 KB Output is correct
3 Correct 26 ms 42616 KB Output is correct
4 Correct 25 ms 42616 KB Output is correct
5 Correct 26 ms 42616 KB Output is correct
6 Correct 26 ms 42616 KB Output is correct
7 Correct 26 ms 42616 KB Output is correct
8 Correct 26 ms 42616 KB Output is correct
9 Correct 27 ms 42620 KB Output is correct
10 Correct 26 ms 42616 KB Output is correct
11 Correct 26 ms 42620 KB Output is correct
12 Correct 26 ms 42616 KB Output is correct
13 Correct 26 ms 42616 KB Output is correct
14 Correct 26 ms 42616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 42616 KB Output is correct
2 Correct 26 ms 42616 KB Output is correct
3 Correct 26 ms 42616 KB Output is correct
4 Correct 25 ms 42616 KB Output is correct
5 Correct 26 ms 42616 KB Output is correct
6 Correct 26 ms 42616 KB Output is correct
7 Correct 26 ms 42616 KB Output is correct
8 Correct 26 ms 42616 KB Output is correct
9 Correct 27 ms 42620 KB Output is correct
10 Correct 26 ms 42616 KB Output is correct
11 Correct 26 ms 42620 KB Output is correct
12 Correct 26 ms 42616 KB Output is correct
13 Correct 26 ms 42616 KB Output is correct
14 Correct 26 ms 42616 KB Output is correct
15 Correct 26 ms 42616 KB Output is correct
16 Correct 26 ms 42616 KB Output is correct
17 Correct 27 ms 42616 KB Output is correct
18 Correct 27 ms 42616 KB Output is correct
19 Correct 27 ms 42616 KB Output is correct
20 Correct 27 ms 42616 KB Output is correct
21 Correct 27 ms 42616 KB Output is correct
22 Correct 26 ms 42616 KB Output is correct
23 Correct 26 ms 42616 KB Output is correct
24 Correct 26 ms 42616 KB Output is correct
25 Correct 27 ms 42616 KB Output is correct
26 Correct 26 ms 42616 KB Output is correct
27 Correct 26 ms 42616 KB Output is correct
28 Correct 26 ms 42616 KB Output is correct
29 Correct 27 ms 42616 KB Output is correct
30 Correct 26 ms 42616 KB Output is correct
31 Correct 26 ms 42616 KB Output is correct
32 Correct 27 ms 42616 KB Output is correct
33 Correct 26 ms 42616 KB Output is correct
34 Correct 27 ms 42616 KB Output is correct
35 Correct 26 ms 42616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 42616 KB Output is correct
2 Correct 26 ms 42616 KB Output is correct
3 Correct 26 ms 42616 KB Output is correct
4 Correct 25 ms 42616 KB Output is correct
5 Correct 26 ms 42616 KB Output is correct
6 Correct 26 ms 42616 KB Output is correct
7 Correct 26 ms 42616 KB Output is correct
8 Correct 26 ms 42616 KB Output is correct
9 Correct 27 ms 42620 KB Output is correct
10 Correct 26 ms 42616 KB Output is correct
11 Correct 26 ms 42620 KB Output is correct
12 Correct 26 ms 42616 KB Output is correct
13 Correct 26 ms 42616 KB Output is correct
14 Correct 26 ms 42616 KB Output is correct
15 Correct 26 ms 42616 KB Output is correct
16 Correct 26 ms 42616 KB Output is correct
17 Correct 27 ms 42616 KB Output is correct
18 Correct 27 ms 42616 KB Output is correct
19 Correct 27 ms 42616 KB Output is correct
20 Correct 27 ms 42616 KB Output is correct
21 Correct 27 ms 42616 KB Output is correct
22 Correct 26 ms 42616 KB Output is correct
23 Correct 26 ms 42616 KB Output is correct
24 Correct 26 ms 42616 KB Output is correct
25 Correct 27 ms 42616 KB Output is correct
26 Correct 26 ms 42616 KB Output is correct
27 Correct 26 ms 42616 KB Output is correct
28 Correct 26 ms 42616 KB Output is correct
29 Correct 27 ms 42616 KB Output is correct
30 Correct 26 ms 42616 KB Output is correct
31 Correct 26 ms 42616 KB Output is correct
32 Correct 27 ms 42616 KB Output is correct
33 Correct 26 ms 42616 KB Output is correct
34 Correct 27 ms 42616 KB Output is correct
35 Correct 26 ms 42616 KB Output is correct
36 Correct 55 ms 42884 KB Output is correct
37 Correct 54 ms 42888 KB Output is correct
38 Correct 55 ms 42884 KB Output is correct
39 Correct 54 ms 42884 KB Output is correct
40 Correct 58 ms 42884 KB Output is correct
41 Correct 54 ms 42884 KB Output is correct
42 Correct 56 ms 42884 KB Output is correct
43 Correct 42 ms 42872 KB Output is correct
44 Correct 49 ms 42888 KB Output is correct
45 Correct 51 ms 42884 KB Output is correct
46 Correct 58 ms 43016 KB Output is correct
47 Correct 52 ms 43012 KB Output is correct
48 Correct 52 ms 42884 KB Output is correct
49 Correct 43 ms 42884 KB Output is correct
50 Correct 52 ms 42884 KB Output is correct
51 Correct 53 ms 42888 KB Output is correct
52 Correct 47 ms 42884 KB Output is correct
53 Correct 50 ms 42884 KB Output is correct
54 Correct 47 ms 42884 KB Output is correct
55 Correct 44 ms 42884 KB Output is correct
56 Correct 43 ms 42884 KB Output is correct