Submission #418038

# Submission time Handle Problem Language Result Execution time Memory
418038 2021-06-04T23:04:26 Z Chaska JJOOII 2 (JOI20_ho_t2) C++11
100 / 100
12 ms 10328 KB
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<long long,long long> ii;
const int N = 6e5+5;
int n,k;
string a;
int J[N],O[N],I[N];
int q;
int howO[N],howI[N],howJ[N];
int main()
{
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n >> k;
    cin >> a;
    q=0;
    for (int i=1;i<=n+n+n;i++) J[i] = O[i] = I[i] = -1;
    
    for (int i=0;i<n;i++) if (a[i]=='J') {
        ++q;
        J[q] = i;
    }
    q=0;
    for (int i=0;i<n;i++) if (a[i]=='O') {
        ++q;
        O[q] = i;
    }
    for (int i=0;i<n;i++) {
        if (a[i]=='O') howO[i]++;
        if (i>0) howO[i] +=howO[i-1];
    }
        q=0;
    for (int i=0;i<n;i++) if (a[i]=='I') {
        ++q;
        I[q] = i;
    }
        for (int i=0;i<n;i++) {
        if (a[i]=='I') howI[i]++;
        if (i>0) howI[i] +=howI[i-1];
    }
    for (int i=0;i<n;i++) {
        if (a[i]=='J') howJ[i]++;
        if (i>0) howJ[i] += howJ[i-1];
    }
    bool y = false;
    int res = n;
    for (int i=k;i<=n;i++) {
        if (J[i]==-1) i = n+1;
        else {
            int p1 = i-(k-1);
            p1 = J[p1];
            int p2 = J[i];
            int os = howO[J[i]];
            int p3 = p2;
            int p4 = O[os+k];
            if (p4 == -1) {
            } else {
                int is = howI[p4];
                int p5 = p4;
                int p6 = I[is+k];
                if (p6 == -1) {
                } else {
                    y = true;
                    int x = howI[p2]-howI[p1] + howO[p2]-howO[p1];
                    int xx = howJ[p4]-howJ[p3] + howI[p4]-howI[p3];
                    int xxx = howJ[p6]-howJ[p5] + howO[p6]-howO[p5];
                    
                    res = min(res,x+xx+xxx);
                }
            }
        }
    }
    if (y) cout << res;
    else cout << -1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 448 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 448 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 11 ms 9432 KB Output is correct
37 Correct 11 ms 10188 KB Output is correct
38 Correct 11 ms 10328 KB Output is correct
39 Correct 11 ms 10128 KB Output is correct
40 Correct 11 ms 10232 KB Output is correct
41 Correct 11 ms 10188 KB Output is correct
42 Correct 12 ms 10188 KB Output is correct
43 Correct 7 ms 6476 KB Output is correct
44 Correct 9 ms 8024 KB Output is correct
45 Correct 11 ms 10200 KB Output is correct
46 Correct 12 ms 10200 KB Output is correct
47 Correct 11 ms 10180 KB Output is correct
48 Correct 11 ms 10200 KB Output is correct
49 Correct 8 ms 7000 KB Output is correct
50 Correct 12 ms 10200 KB Output is correct
51 Correct 11 ms 10200 KB Output is correct
52 Correct 12 ms 9816 KB Output is correct
53 Correct 12 ms 10200 KB Output is correct
54 Correct 8 ms 10200 KB Output is correct
55 Correct 8 ms 10200 KB Output is correct
56 Correct 8 ms 10200 KB Output is correct