#include <bits/stdc++.h>
using namespace std;
int n, k, J[200001], O[200001], I[200001];
vector<int> J_gdzie, O_gdzie, I_gdzie;
string word;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
cin >> word;
if(word[0] == 'J'){
J_gdzie.push_back(0);
J[0]++;
}
if(word[0] == 'O'){
O_gdzie.push_back(0);
O[0]++;
}
if(word[0] == 'I'){
I_gdzie.push_back(0);
I[0]++;
}
for(int i = 1; i < n; i++){
//cout << J[i] << " " << I[i] << " " << O[i] << " " << word[i] << endl;
J[i] = J[i - 1];
O[i] = O[i - 1];
I[i] = I[i - 1];
if(word[i] == 'J'){
J_gdzie.push_back(i);
J[i]++;
}
if(word[i] == 'O'){
O_gdzie.push_back(i);
O[i]++;
}
if(word[i] == 'I'){
I_gdzie.push_back(i);
I[i]++;
}
}
for(int i = 0; i < n; i++){
//cout << J[i] << " " << O[i] << " " << I[i] << endl;
}
int wynik = 200001;
for(int i = 0; i < J_gdzie.size(); i++){
int ind_j = J_gdzie[i];
if(J_gdzie.size() - J[ind_j] + 1 >= k){
if(O[J_gdzie[i + k - 1]] >= O_gdzie.size()){
continue;
}
int ind_o = O_gdzie[O[J_gdzie[i + k - 1]]];
if(O_gdzie.size() - O[ind_o] + 1 >= k){
if(I[O_gdzie[O[J_gdzie[k - 1]] + k - 1]] >= I_gdzie.size()){
continue;
}
int ind_i = I_gdzie[I[O_gdzie[O[J_gdzie[k - 1]] + k - 1]]];
if(I_gdzie.size() - I[ind_i] + 1 >= k){
wynik = min(wynik, I_gdzie[I[O_gdzie[O[J_gdzie[k - 1]] + k - 1]] + k - 1] - ind_j + 1 - 3 * k);
}
}
}
}
if(wynik == 200001){
wynik = -1;
}
cout << wynik;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0; i < J_gdzie.size(); i++){
| ~~^~~~~~~~~~~~~~~~
ho_t2.cpp:52:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
52 | if(J_gdzie.size() - J[ind_j] + 1 >= k){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
ho_t2.cpp:53:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | if(O[J_gdzie[i + k - 1]] >= O_gdzie.size()){
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ho_t2.cpp:57:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
57 | if(O_gdzie.size() - O[ind_o] + 1 >= k){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
ho_t2.cpp:58:58: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if(I[O_gdzie[O[J_gdzie[k - 1]] + k - 1]] >= I_gdzie.size()){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ho_t2.cpp:62:50: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
62 | if(I_gdzie.size() - I[ind_i] + 1 >= k){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |