#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,k,o;
string napis;
cin >> n >> k >> napis;
queue<int>indexJ,indexI,indexO;
vector<int>J1,J2,I1,I2,O1,O2;
for(int i=0;i<n;++i){
if(napis[i]=='O')
indexO.push(i);
if(napis[i]=='J')
indexJ.push(i);
if(napis[i]=='I')
indexI.push(i);
if(indexJ.size()==k){
J1.push_back(indexJ.front());
J2.push_back(i);
indexJ.pop();
}
if(indexO.size()==k){
O1.push_back(indexO.front());
O2.push_back(i);
indexO.pop();
}
if(indexI.size()==k){
I1.push_back(indexI.front());
I2.push_back(i);
indexI.pop();
}
}
int wynik=2000007;
vector<int>::iterator it1,it2;
for(int i=0;i<J1.size();++i){
it1=lower_bound(O1.begin(),O1.end(),J2[i]);
if(it1!=O1.end()){
it2=lower_bound(I1.begin(),I1.end(),O2[it1-O1.begin()]);
/*cout << J1[i] << ' '<< J2[i] << endl;
cout << O1[it1-O1.begin()] << ' ' << O2[it1-O1.begin()] << endl;
cout << I1[it2-I1.begin()] << ' ' << I2[it2-I1.begin()] << endl;
*/
if(it2!=I1.end()){
int s3=I2[it2-I1.begin()]-J1[i]+1-3*k;
wynik=min(s3,wynik);
}
}
}
if(wynik!=2000007)
cout << wynik;
else
cout << -1;
return 0;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:25: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
19 | if(indexJ.size()==k){
| ~~~~~~~~~~~~~^~~
ho_t2.cpp:24:25: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
24 | if(indexO.size()==k){
| ~~~~~~~~~~~~~^~~
ho_t2.cpp:29:25: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
29 | if(indexI.size()==k){
| ~~~~~~~~~~~~~^~~
ho_t2.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<J1.size();++i){
| ~^~~~~~~~~~
ho_t2.cpp:6:13: warning: unused variable 'o' [-Wunused-variable]
6 | int n,k,o;
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 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 |
336 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 |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 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 |
336 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 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 |
336 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 |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 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 |
336 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 |
9 ms |
2384 KB |
Output is correct |
37 |
Correct |
12 ms |
3048 KB |
Output is correct |
38 |
Correct |
11 ms |
2692 KB |
Output is correct |
39 |
Correct |
9 ms |
2420 KB |
Output is correct |
40 |
Correct |
7 ms |
2128 KB |
Output is correct |
41 |
Correct |
9 ms |
2268 KB |
Output is correct |
42 |
Correct |
10 ms |
2900 KB |
Output is correct |
43 |
Correct |
4 ms |
1616 KB |
Output is correct |
44 |
Correct |
5 ms |
2220 KB |
Output is correct |
45 |
Correct |
7 ms |
2288 KB |
Output is correct |
46 |
Correct |
7 ms |
2440 KB |
Output is correct |
47 |
Correct |
7 ms |
2392 KB |
Output is correct |
48 |
Correct |
7 ms |
2488 KB |
Output is correct |
49 |
Correct |
5 ms |
1760 KB |
Output is correct |
50 |
Correct |
7 ms |
2452 KB |
Output is correct |
51 |
Correct |
6 ms |
2468 KB |
Output is correct |
52 |
Correct |
5 ms |
1756 KB |
Output is correct |
53 |
Correct |
5 ms |
1756 KB |
Output is correct |
54 |
Correct |
6 ms |
3152 KB |
Output is correct |
55 |
Correct |
4 ms |
2012 KB |
Output is correct |
56 |
Correct |
3 ms |
1500 KB |
Output is correct |