# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1089083 |
2024-09-15T22:47:35 Z |
Izzy |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
28 ms |
3316 KB |
#include <iostream>
#include <string>
#include <vector>
// #include <unordered_map>
using namespace std;
string s;
int n;
int k;
int find(int target, int low, vector<int> &arr) {
int high = n;
int working = -1;
int mid;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] >= target) {
working = mid;
high = mid - 1;
}
else if (arr[mid] < target) {
low = mid + 1;
}
}
return working;
}
int main() {
cin >> n;
cin >> k;
cin >> s;
vector<int> jPref = {0};
vector<int> oPref = {0};
vector<int> iPref = {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++;
}
jPref.push_back(jCount);
oPref.push_back(oCount);
iPref.push_back(iCount);
}
int counter = 200001;
for (int p = 1; p < n + 1; p++) {
int jPos = find(jPref[p - 1] + k, p, jPref);
// cout << jPos << ' ';
if (jPos == -1) {
break;
}
int oPos = find(oPref[jPos] + k, jPos, oPref);
// cout << oPos << ' ';
if (oPos == -1) {
break;
}
int iPos = find(iPref[oPos] + k, oPos, iPref);
// cout << iPos << ' ';
if (iPos == -1) {
break;
}
// cout << counter << endl;
counter = min(counter, iPos - p - 3 * k + 1);
}
if (counter == 200001) {
counter = -1;
}
cout << counter;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
420 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
436 KB |
Output is correct |
18 |
Correct |
0 ms |
440 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
436 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
420 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
436 KB |
Output is correct |
18 |
Correct |
0 ms |
440 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
436 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
19 ms |
3028 KB |
Output is correct |
37 |
Correct |
20 ms |
3308 KB |
Output is correct |
38 |
Correct |
21 ms |
3268 KB |
Output is correct |
39 |
Correct |
19 ms |
3272 KB |
Output is correct |
40 |
Correct |
10 ms |
3268 KB |
Output is correct |
41 |
Correct |
17 ms |
3272 KB |
Output is correct |
42 |
Correct |
28 ms |
3272 KB |
Output is correct |
43 |
Correct |
4 ms |
2260 KB |
Output is correct |
44 |
Correct |
6 ms |
2876 KB |
Output is correct |
45 |
Correct |
6 ms |
3208 KB |
Output is correct |
46 |
Correct |
6 ms |
3272 KB |
Output is correct |
47 |
Correct |
6 ms |
3268 KB |
Output is correct |
48 |
Correct |
7 ms |
3272 KB |
Output is correct |
49 |
Correct |
5 ms |
3028 KB |
Output is correct |
50 |
Correct |
7 ms |
3316 KB |
Output is correct |
51 |
Correct |
7 ms |
3272 KB |
Output is correct |
52 |
Correct |
6 ms |
3272 KB |
Output is correct |
53 |
Correct |
7 ms |
3272 KB |
Output is correct |
54 |
Correct |
10 ms |
3276 KB |
Output is correct |
55 |
Correct |
6 ms |
3272 KB |
Output is correct |
56 |
Correct |
5 ms |
3272 KB |
Output is correct |