Submission #959870

# Submission time Handle Problem Language Result Execution time Memory
959870 2024-04-09T08:58:50 Z Champ_Naman JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
26 ms 5864 KB
#include<bits/stdc++.h>
#define int long long
#define nl endl
using namespace std;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);

    int n, k;
    cin>>n>>k;
    string s; cin>>s;
 
    vector<int> Jcnt(n), Ocnt(n), Icnt(n);
    Jcnt[0] = (s[0] == 'J'), Ocnt[0] = (s[0] == 'O'), Icnt[0] = (s[0] == 'I');
    for(int i=1; i<n; i++){
        Jcnt[i] = Jcnt[i-1] + (s[i] == 'J');
        Ocnt[i] = Ocnt[i-1] + (s[i] == 'O');
        Icnt[i] = Icnt[i-1] + (s[i] == 'I');
    }

    int ans = 1e18;
    for(int i=0; i<n; i++){
        int Jstart = lower_bound(Jcnt.begin(), Jcnt.end(), i+1) - Jcnt.begin();

        int Jend = lower_bound(Jcnt.begin(), Jcnt.end(), i + k) - Jcnt.begin();
        if(Jend >= n) continue;
        int Oend = lower_bound(Ocnt.begin(), Ocnt.end(), Ocnt[Jend] + k) - Ocnt.begin();
        if(Oend >= n) continue;
        int Iend = lower_bound(Icnt.begin(), Icnt.end(), Icnt[Oend] + k) - Icnt.begin();
        if(Iend >= n) continue;

        //if(Jend >= n or Oend >= n or Iend >= n) continue;

        ans = min(ans, (Iend - Jstart + 1) - (3*k));
    }
 
    if(ans == 1e18) cout<<-1;
    else cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 456 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 496 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 452 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 456 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 496 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 452 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 20 ms 5096 KB Output is correct
37 Correct 20 ms 5604 KB Output is correct
38 Correct 26 ms 5672 KB Output is correct
39 Correct 24 ms 5864 KB Output is correct
40 Correct 19 ms 5608 KB Output is correct
41 Correct 23 ms 5688 KB Output is correct
42 Correct 25 ms 5604 KB Output is correct
43 Correct 11 ms 3676 KB Output is correct
44 Correct 16 ms 4324 KB Output is correct
45 Correct 18 ms 5608 KB Output is correct
46 Correct 19 ms 5608 KB Output is correct
47 Correct 18 ms 5860 KB Output is correct
48 Correct 19 ms 5608 KB Output is correct
49 Correct 15 ms 3816 KB Output is correct
50 Correct 20 ms 5608 KB Output is correct
51 Correct 19 ms 5680 KB Output is correct
52 Correct 14 ms 5352 KB Output is correct
53 Correct 18 ms 5608 KB Output is correct
54 Correct 17 ms 5540 KB Output is correct
55 Correct 15 ms 5608 KB Output is correct
56 Correct 13 ms 5608 KB Output is correct