답안 #220668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
220668 2020-04-08T11:24:14 Z srvlt JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
16 ms 7180 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 2e5 + 123;
int n, k, p[3][N], sf[3][N];
int l[3][N], r[3][N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    string s;
    cin >> n >> k >> s;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            p[j][i] = p[j][i - 1];
        }
        if (s[i - 1] == 'J') {
            p[0][i]++;
            l[0][p[0][i]] = i;
        }
        if (s[i - 1] == 'O') {
            p[1][i]++;
            l[1][p[1][i]] = i;
        }
        if (s[i - 1] == 'I') {
            p[2][i]++;
            l[2][p[2][i]] = i;
        }
    }
    for (int i = n; i >= 1; i--) {
        for (int j = 0; j < 3; j++) {
            sf[j][i] = sf[j][i + 1];
        }
        if (s[i - 1] == 'J') {
            sf[0][i]++;
            r[0][sf[0][i]] = i;
        }
        if (s[i - 1] == 'O') {
            sf[1][i]++;
            r[1][sf[1][i]] = i;
        }
        if (s[i - 1] == 'I') {
            sf[2][i]++;
            r[2][sf[2][i]] = i;
        }
    }
    int j = 1, ans = N;
    for (int i = 1; i <= n; i++) {
        while (j < i && p[1][i] - p[1][j] >= k) {
            j++;
        }
        if (s[i - 1] == 'O' && p[1][i] - p[1][j - 1] == k) {
            if (r[0][sf[0][j] + k] && l[2][p[2][i] + k]) {
                ans = min(ans, l[2][p[2][i] + k] - r[0][sf[0][j] + k]);
            }
        }
    }
    if (ans == N) {
        cout << -1;
        return 0;
    }
    cout << ans - 3 * k + 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 432 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 432 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 640 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 432 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 640 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 13 ms 6668 KB Output is correct
37 Correct 13 ms 7180 KB Output is correct
38 Correct 13 ms 7180 KB Output is correct
39 Correct 14 ms 7052 KB Output is correct
40 Correct 13 ms 7180 KB Output is correct
41 Correct 15 ms 7180 KB Output is correct
42 Correct 14 ms 7180 KB Output is correct
43 Correct 10 ms 4608 KB Output is correct
44 Correct 11 ms 5644 KB Output is correct
45 Correct 13 ms 7180 KB Output is correct
46 Correct 13 ms 7180 KB Output is correct
47 Correct 14 ms 7180 KB Output is correct
48 Correct 14 ms 7180 KB Output is correct
49 Correct 11 ms 5004 KB Output is correct
50 Correct 16 ms 7156 KB Output is correct
51 Correct 14 ms 7180 KB Output is correct
52 Correct 12 ms 6924 KB Output is correct
53 Correct 13 ms 7180 KB Output is correct
54 Correct 10 ms 7180 KB Output is correct
55 Correct 10 ms 7180 KB Output is correct
56 Correct 10 ms 7180 KB Output is correct