# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
384003 |
2021-03-31T07:38:53 Z |
aryan12 |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
18 ms |
3312 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> J, O, I;
int Check(int start_idx, int k) {
int start = start_idx;
int l = 0, r = J.size();
int mid, pos = J.size();
while(l <= r) {
mid = (l + r) / 2;
if(J[mid] >= start_idx) {
pos = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
if(pos + k - 1 >= J.size())
return -1;
l = 0;
r = O.size();
start_idx = J[pos + k - 1];
pos = O.size();
while(l <= r) {
mid = (l + r) / 2;
if(O[mid] >= start_idx) {
pos = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
if(pos + k - 1 >= O.size())
return -1;
l = 0;
r = I.size();
start_idx = O[pos + k - 1];
pos = I.size();
while(l <= r) {
mid = (l + r) / 2;
if(I[mid] >= start_idx) {
pos = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
if(pos + k - 1 >= I.size())
return -1;
int ending = I[pos + k - 1];
return ending - start + 1 - 3 * k;
}
void Solve() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
for(int i = 0; i < s.size(); i++) {
if(s[i] == 'J') {
J.push_back(i);
}
else if(s[i] == 'O') {
O.push_back(i);
}
else {
I.push_back(i);
}
}
int ans = INT_MAX;
for(int i = 0; i < s.size(); i++) {
if(s[i] == 'J') {
int x = Check(i, k);
if(x == -1) {
break;
}
else {
ans = min(ans, x);
}
}
}
cout << ((ans == INT_MAX) ? (-1LL) : (ans)) << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
Solve();
return 0;
}
Compilation message
ho_t2.cpp: In function 'long long int Check(long long int, long long int)':
ho_t2.cpp:21:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if(pos + k - 1 >= J.size())
| ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:37:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | if(pos + k - 1 >= O.size())
| ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:53:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | if(pos + k - 1 >= I.size())
| ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp: In function 'void Solve()':
ho_t2.cpp:64:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
ho_t2.cpp:76:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
16 ms |
2396 KB |
Output is correct |
37 |
Correct |
18 ms |
2912 KB |
Output is correct |
38 |
Correct |
18 ms |
2892 KB |
Output is correct |
39 |
Correct |
16 ms |
3000 KB |
Output is correct |
40 |
Correct |
8 ms |
3180 KB |
Output is correct |
41 |
Correct |
13 ms |
3044 KB |
Output is correct |
42 |
Correct |
18 ms |
2916 KB |
Output is correct |
43 |
Correct |
4 ms |
1856 KB |
Output is correct |
44 |
Correct |
4 ms |
2152 KB |
Output is correct |
45 |
Correct |
6 ms |
2984 KB |
Output is correct |
46 |
Correct |
7 ms |
3048 KB |
Output is correct |
47 |
Correct |
6 ms |
3044 KB |
Output is correct |
48 |
Correct |
6 ms |
3016 KB |
Output is correct |
49 |
Correct |
4 ms |
1892 KB |
Output is correct |
50 |
Correct |
6 ms |
3012 KB |
Output is correct |
51 |
Correct |
6 ms |
3044 KB |
Output is correct |
52 |
Correct |
5 ms |
2520 KB |
Output is correct |
53 |
Correct |
6 ms |
2932 KB |
Output is correct |
54 |
Correct |
11 ms |
3312 KB |
Output is correct |
55 |
Correct |
7 ms |
3312 KB |
Output is correct |
56 |
Correct |
5 ms |
3312 KB |
Output is correct |