Submission #535302

# Submission time Handle Problem Language Result Execution time Memory
535302 2022-03-10T01:30:06 Z Koying JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
6 ms 876 KB
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("Ofast")
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define cmax(a, b) a = max(a, b)
#define cmin(a, b) a = min(a, b)
#define MEM(x, n) memset(x, n, sizeof(x))
#define pii pair<int, int>
#define pdd pair<double, double>
#define DB(x) cerr << #x << " " << x << endl;
#define endl "\n"
#define Koying ios::sync_with_stdio(0), cin.tie(0)
#define lowbit(x) x &(-x)
const int INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;

#define MAXN 200005

int n, k;
string s;

void sol() {
    cin >> n >> k;
    cin >> s;
    int mn = INF;
    //DB(s);
    int a, b, c, d;
    a = b = c = d = -1;
    int cntJ, cntO, cntI;
    cntJ = cntO = cntI = 0;
    for (int i = 0; i < n; i++) {
        while (d + 1 <= i) {
            d++;
            cntI += s[d] == 'I';
        }
        while (c + 1 < d && cntI - (s[c + 1] == 'I') >= k) {
            c++;
            cntO += s[c] == 'O';
            cntI -= s[c] == 'I';
        }
        while (b + 1 < c && cntO - (s[b + 1] == 'O') >= k) {
            b++;
            cntJ += s[b] == 'J';
            cntO -= s[b] == 'O';
        }
        while (a + 1 < b && cntJ - (s[a + 1] == 'J') >= k) {
            a++;
            cntJ -= s[a] == 'J';
        }
        if (cntJ >= k && cntO >= k && cntI >= k)
            cmin(mn, d - a);
        //cout << a << " " << b << " " << c << " " << d << endl;
        //cout << cntJ << " " << cntO << " " << cntI << endl;
    }
    if (mn == INF) {
        cout << -1 << endl;
        return;
    }
    cout << mn - 3 * k << endl;
}

signed main()
{
    Koying;
    int t = 1;
    //cin >> t;
    sol();
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:66:9: warning: unused variable 't' [-Wunused-variable]
   66 |     int t = 1;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 3 ms 608 KB Output is correct
37 Correct 4 ms 608 KB Output is correct
38 Correct 4 ms 608 KB Output is correct
39 Correct 4 ms 608 KB Output is correct
40 Correct 4 ms 852 KB Output is correct
41 Correct 6 ms 852 KB Output is correct
42 Correct 5 ms 852 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 736 KB Output is correct
45 Correct 3 ms 864 KB Output is correct
46 Correct 3 ms 852 KB Output is correct
47 Correct 3 ms 852 KB Output is correct
48 Correct 3 ms 876 KB Output is correct
49 Correct 2 ms 724 KB Output is correct
50 Correct 3 ms 848 KB Output is correct
51 Correct 4 ms 848 KB Output is correct
52 Correct 2 ms 864 KB Output is correct
53 Correct 2 ms 852 KB Output is correct
54 Correct 2 ms 852 KB Output is correct
55 Correct 2 ms 852 KB Output is correct
56 Correct 2 ms 852 KB Output is correct