Submission #1101826

# Submission time Handle Problem Language Result Execution time Memory
1101826 2024-10-17T00:04:37 Z BlueGlaucus1 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
24 ms 3428 KB
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int n; 
 
int find(int target, int low, vector<int> &arr) {
    int high = n;
    int val = -1;
    int mid;
 
    while (low <= high) {
        mid = (low + high) / 2;
        if (arr[mid] >= target) {
            val = mid;
            high = mid - 1;
        } 
        else if (arr[mid] < target) {
            low = mid + 1;
        }
    }
    return val;
}

int main() {
    string s;
    int k;
    cin >> n;
    cin >> k;
    cin >> s;
 
    vector<int> prefixj ;
    vector<int> prefixo;
    vector<int> prefixi;
    prefixj.push_back(0);
    prefixi.push_back(0);
    prefixo.push_back(0);
 
    int jCount = 0;
    int oCount = 0;
    int iCount = 0;
    for (auto p: s) {
        if (p == 'J') {
            jCount++;
        }
        else if (p == 'O') {
            oCount++;
        }
        else if (p == 'I') {
            iCount++;
        }
        prefixj.push_back(jCount);
        prefixo.push_back(oCount);
        prefixi.push_back(iCount); 
    }
    int answer = 200001;
 
    for (int i = 1; i <=n; i++) {
        int position_of_j = find(prefixj[i-1] + k, i, prefixj);
        if (position_of_j == -1) {
            break;
        }
        int position_of_o = find(prefixo[position_of_j] + k, position_of_j, prefixo);
        if (position_of_o == -1) {
            break;
        }

        int position_of_i = find(prefixi[position_of_o] + k, position_of_o, prefixi);
        if (position_of_i == -1) {
            break;
        }
        answer = min(answer, position_of_i - i - 3 * k + 1);
    }
    if (answer == 200001) {
        answer = -1;
    }
    cout << answer;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 436 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 440 KB Output is correct
31 Correct 1 ms 504 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 436 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 440 KB Output is correct
31 Correct 1 ms 504 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 21 ms 3028 KB Output is correct
37 Correct 24 ms 3428 KB Output is correct
38 Correct 23 ms 3264 KB Output is correct
39 Correct 21 ms 3264 KB Output is correct
40 Correct 11 ms 3420 KB Output is correct
41 Correct 19 ms 3264 KB Output is correct
42 Correct 24 ms 3264 KB Output is correct
43 Correct 5 ms 2252 KB Output is correct
44 Correct 7 ms 3020 KB Output is correct
45 Correct 8 ms 3264 KB Output is correct
46 Correct 8 ms 3428 KB Output is correct
47 Correct 8 ms 3264 KB Output is correct
48 Correct 8 ms 3372 KB Output is correct
49 Correct 6 ms 3020 KB Output is correct
50 Correct 8 ms 3264 KB Output is correct
51 Correct 8 ms 3376 KB Output is correct
52 Correct 7 ms 3264 KB Output is correct
53 Correct 8 ms 3272 KB Output is correct
54 Correct 11 ms 3376 KB Output is correct
55 Correct 9 ms 3428 KB Output is correct
56 Correct 7 ms 3264 KB Output is correct