// Author : Coder_030
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define vi vector<int>
#define MOD 1000000007
#define iter(a) for(auto &u : a)
#define f(i, a, b) for(int i = a; i < b; i ++)
#define pii pair<int, int>
#define pb push_back
#define all(a) a.begin(), a.end()
void solution() {
int n, k; cin >> n >> k;
string s; cin >> s;
string opt = "";
f(i,0,k) opt += 'J'; f(i,0,k) opt += 'O'; f(i,0,k) opt += 'I';
int ans = LLONG_MAX;
f(mask, 0, 1 << n) {
string temp = "";
f(i, 0, n) {
if(mask & (1 << i)) {
temp += s[i];
}
}
if(temp == opt) {
int l = 0;
while(!(mask & (1 << l))) {
l++;
}
int r =n-1;
while(!(mask & (1 << r))) {
r--;
}
int c =0 ;
f(i, l, r+1) {
if(!(mask & (1 << i))) {
c++;
}
}
ans = min(ans, c);
}
}
int res = (ans == LLONG_MAX) ? -1 : ans;
cout << res << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solution();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |