#include<bits/stdc++.h>
#ifdef _DEBUG
#define ls(x) << (x) << ", "
#define lv(x) << #x << ": " << flush << (x) << ", "
#define pr(x) cout << "Line: " << __LINE__ << ", " x << endl;
#else
#define ls(x)
#define lv(x)
#define pr(x) ;
#endif
using namespace std;
typedef unsigned int uint;
constexpr char J = 'J';
constexpr char O = 'O';
constexpr char I = 'I';
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
uint n, k;
cin >> n >> k;
string a;
cin >> a;
uint result = 1e9;
for (uint i = 0; i < (n - 3*k + 1); i++) {
if (a[i] != J) continue;
pr(lv(i) lv(a[i]))
uint curr = 0;
uint num_j = 1;
uint j = i + 1; // not current
if (k > 1) {
for (; j < n; j++) {
if (a[j] == J) {
pr(ls("in j") lv(j) lv(a[j]))
num_j++;
if (num_j == k){
break;
}
} else {
pr(ls("not j") lv(j) lv(a[j]))
curr++;
}
}
j++;
pr(lv(num_j))
if (num_j < k) {
break; // już nie będzie
}
pr()
}
uint num_o = 0;
for (; j < n; j++) {
if (a[j] == O) {
pr(ls("in o") lv(j) lv(a[j]))
num_o++;
if (num_o == k) {
break;
}
} else {
pr(ls("not o") lv(j) lv(a[j]))
curr++;
}
}
j++;
pr(lv(num_o))
if (num_o < k) {
break;
}
pr()
uint num_i = 0;
for (; j < n; j++) {
if (a[j] == I) {
pr(ls("in i") lv(j) lv(a[j]))
num_i++;
if (num_i == k) {
break;
}
} else {
pr(ls("not i") lv(j) lv(a[j]))
curr++;
}
}
j++;
pr(lv(num_i))
if (num_i < k) {
break;
}
pr()
result = min(result, curr);
}
if (result == 1e9) {
cout << -1 << '\n';
return 0;
}
cout << result << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |