Submission #203107

# Submission time Handle Problem Language Result Execution time Memory
203107 2020-02-19T11:35:41 Z godwind JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
191 ms 48248 KB
// O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
// #include <random>
#include <iomanip>
#include <bitset>
#include <cassert>
 
using namespace std;
 
#define y1 y11
#define double long double
#define less less228
#define left left228
#define right right228
#define list list228
 
 
 
template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}
 
 
// random_device rnd;
 
// template<typename T> void shuffle(vector< T > &v) {
//     for (int i = 1; i < (int)v.size(); ++i) {
//         swap(v[rnd() % i], v[i]);
//     }
//     for (int i = (int)v.size() - 1; i; --i) {
//         swap(v[rnd() % i], v[i]);
//     }
// }

const int N = 200 * 1000 + 228;
const int LG = 20;

int s[N], last[3];
int p[N][3][LG];


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, K;
    cin >> n >> K;
    for (int i = 1; i <= n; ++i) {
        char c;
        cin >> c;
        if (c == 'J') {
            s[i] = 0;
        } else if (c == 'O') {
            s[i] = 1;
        } else {
            s[i] = 2;
        }
    }
    last[0] = last[1] = last[2] = n + 1;
    for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 20; ++k) {
            p[n + 1][j][k] = n + 1;
        }
    }
    for (int i = n; i; --i) {
        for (int j = 0; j < 3; ++j) {
            p[i][j][0] = last[j];
            for (int k = 1; k < LG; ++k) {
                p[i][j][k] = p[p[i][j][k - 1]][j][k - 1];
            }
        }
        last[s[i]] = i;
    }
    int answer = n + 1;
    for (int i = 1; i <= n; ++i) {
        int pos = i;
        for (int j = 0; j < 3; ++j) {
            int curK = K;
            if (s[pos] == j) curK--;
            for (int t = 0; t < LG; ++t) {
                if ((curK >> t) & 1) {
                    pos = p[pos][j][t];
                }
            }
        }
        if (pos == n + 1) continue;
        uin(answer, pos - i + 1 - 3 * K);
    }
    if (answer == n + 1) answer = -1;
    cout << answer << '\n';
    return 0;
}
// RU_023
 
 
// 
// OJIJOIOIIJ



# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 1016 KB Output is correct
16 Correct 6 ms 1144 KB Output is correct
17 Correct 6 ms 1016 KB Output is correct
18 Correct 6 ms 760 KB Output is correct
19 Correct 6 ms 1016 KB Output is correct
20 Correct 6 ms 1016 KB Output is correct
21 Correct 6 ms 1016 KB Output is correct
22 Correct 7 ms 1016 KB Output is correct
23 Correct 5 ms 764 KB Output is correct
24 Correct 6 ms 1020 KB Output is correct
25 Correct 6 ms 1144 KB Output is correct
26 Correct 6 ms 1016 KB Output is correct
27 Correct 6 ms 1016 KB Output is correct
28 Correct 6 ms 1016 KB Output is correct
29 Correct 6 ms 1016 KB Output is correct
30 Correct 6 ms 1016 KB Output is correct
31 Correct 6 ms 632 KB Output is correct
32 Correct 6 ms 1016 KB Output is correct
33 Correct 6 ms 1144 KB Output is correct
34 Correct 6 ms 1016 KB Output is correct
35 Correct 6 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 1016 KB Output is correct
16 Correct 6 ms 1144 KB Output is correct
17 Correct 6 ms 1016 KB Output is correct
18 Correct 6 ms 760 KB Output is correct
19 Correct 6 ms 1016 KB Output is correct
20 Correct 6 ms 1016 KB Output is correct
21 Correct 6 ms 1016 KB Output is correct
22 Correct 7 ms 1016 KB Output is correct
23 Correct 5 ms 764 KB Output is correct
24 Correct 6 ms 1020 KB Output is correct
25 Correct 6 ms 1144 KB Output is correct
26 Correct 6 ms 1016 KB Output is correct
27 Correct 6 ms 1016 KB Output is correct
28 Correct 6 ms 1016 KB Output is correct
29 Correct 6 ms 1016 KB Output is correct
30 Correct 6 ms 1016 KB Output is correct
31 Correct 6 ms 632 KB Output is correct
32 Correct 6 ms 1016 KB Output is correct
33 Correct 6 ms 1144 KB Output is correct
34 Correct 6 ms 1016 KB Output is correct
35 Correct 6 ms 1016 KB Output is correct
36 Correct 127 ms 44768 KB Output is correct
37 Correct 137 ms 48120 KB Output is correct
38 Correct 151 ms 48248 KB Output is correct
39 Correct 164 ms 47608 KB Output is correct
40 Correct 176 ms 48120 KB Output is correct
41 Correct 182 ms 48124 KB Output is correct
42 Correct 163 ms 48120 KB Output is correct
43 Correct 103 ms 29944 KB Output is correct
44 Correct 126 ms 37368 KB Output is correct
45 Correct 189 ms 48120 KB Output is correct
46 Correct 188 ms 48120 KB Output is correct
47 Correct 179 ms 48120 KB Output is correct
48 Correct 184 ms 48248 KB Output is correct
49 Correct 112 ms 32248 KB Output is correct
50 Correct 169 ms 48248 KB Output is correct
51 Correct 191 ms 48136 KB Output is correct
52 Correct 160 ms 46328 KB Output is correct
53 Correct 165 ms 48120 KB Output is correct
54 Correct 95 ms 48248 KB Output is correct
55 Correct 104 ms 48120 KB Output is correct
56 Correct 116 ms 48120 KB Output is correct