# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1114928 |
2024-11-19T19:54:57 Z |
AdamGS |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
1192 ms |
2184 KB |
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
int bin(int co, vector<int> v) {
int pocz = 0, kon = v.size() - 1, sr;
while(pocz < kon) {
sr = (pocz + kon) / 2;
if (v[sr] < co) {
pocz = sr + 1;
}
else {
kon = sr;
}
}
return pocz;
}
int main() {
int n, k;
cin >> n >> k;
string joi;
cin >> joi;
vector<vector<int>> od(3, vector<int>());
for (int i = 0; i < n; i++) {
if (joi[i] == 'J') {
od[0].push_back(i);
}
else if(joi[i] == 'O') {
od[1].push_back(i);
}
else if(joi[i] == 'I') {
od[2].push_back(i);
}
}
int w = -1;
for (int i = 0; i < od[0].size(); i++) {
int ak = i;
if (i + k - 1 <= od[0].size() - 1) {
ak = od[0][i + k - 1];
if (upper_bound(od[1].begin(), od[1].end(), ak) != od[1].end()) {
ak = *upper_bound(od[1].begin(), od[1].end(), ak);
ak = bin(ak, od[1]);
if (ak + k - 1 <= od[1].size() - 1) {
ak = od[1][ak + k - 1];
if (upper_bound(od[2].begin(), od[2].end(), ak) != od[2].end()) {
ak = *upper_bound(od[2].begin(), od[2].end(), ak);
ak = bin(ak, od[2]);
if (ak + k - 1 <= od[2].size() - 1) {
ak = od[2][ak + k - 1];
if (ak - od[0][i] + 1 - 3 * k < w || w == -1) {
w = ak - od[0][i] + 1 - 3 * k;
}
}
}
}
}
}
}
cout << w;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < od[0].size(); i++) {
| ~~^~~~~~~~~~~~~~
ho_t2.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if (i + k - 1 <= od[0].size() - 1) {
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
ho_t2.cpp:45:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if (ak + k - 1 <= od[1].size() - 1) {
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
ho_t2.cpp:50:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | if (ak + k - 1 <= od[2].size() - 1) {
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
440 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
592 KB |
Output is correct |
28 |
Correct |
1 ms |
436 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
436 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
440 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
592 KB |
Output is correct |
28 |
Correct |
1 ms |
436 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
436 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
996 ms |
1740 KB |
Output is correct |
37 |
Correct |
1136 ms |
1820 KB |
Output is correct |
38 |
Correct |
1094 ms |
1972 KB |
Output is correct |
39 |
Correct |
945 ms |
1984 KB |
Output is correct |
40 |
Correct |
543 ms |
2008 KB |
Output is correct |
41 |
Correct |
860 ms |
1944 KB |
Output is correct |
42 |
Correct |
943 ms |
1820 KB |
Output is correct |
43 |
Correct |
211 ms |
1380 KB |
Output is correct |
44 |
Correct |
271 ms |
1496 KB |
Output is correct |
45 |
Correct |
552 ms |
2008 KB |
Output is correct |
46 |
Correct |
555 ms |
1996 KB |
Output is correct |
47 |
Correct |
481 ms |
2004 KB |
Output is correct |
48 |
Correct |
542 ms |
2004 KB |
Output is correct |
49 |
Correct |
198 ms |
1212 KB |
Output is correct |
50 |
Correct |
536 ms |
1992 KB |
Output is correct |
51 |
Correct |
537 ms |
2000 KB |
Output is correct |
52 |
Correct |
69 ms |
1876 KB |
Output is correct |
53 |
Correct |
103 ms |
1748 KB |
Output is correct |
54 |
Correct |
1192 ms |
2008 KB |
Output is correct |
55 |
Correct |
393 ms |
2012 KB |
Output is correct |
56 |
Correct |
7 ms |
2184 KB |
Output is correct |