#include <bitset>
#include <algorithm>
#include <numeric>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define NMAX 200001
#define KMAX 15
#define pb push_back
#define MOD 1000000007
#define nl '\n'
#define INF 0x3f3f3f3f
#define pii1 pair<int, pair<int,int>> (1,(1,2));
#define pii pair<int,int>
#define tpl tuple<int, int,int,int>
#define int long long
using namespace std;
ifstream fin("data.in");
ofstream fout("data.out");
int n,k;
string s;
signed main() {
cin>>n>>k;
cin>>s;
int mini=INF;
for(int i=0;i<s.size();++i)
{
int sum=0;
bool ok=false;
if(s[i]=='J')
{
int cntJ=1,cntO=0,cntI=0;
for(int j=i+1;j<s.size();++j)
{
if(cntJ==k && cntO==k && cntI==k) {
ok=true;
break;
}
if(s[j]=='J'&& cntJ<k)
{
cntJ++;
}
else if(s[j]=='J'&& cntJ==k)
sum++;
if(s[j]=='O'&& cntJ==k && cntO<k)
{
cntO++;
}
else if(s[j]=='O'&& cntO==k)
sum++;
if(s[j]=='I'&& cntJ==k && cntO==k && cntI<k)
cntI++;
else if(s[j]=='I'&& cntO<k)
sum++;
}
}
if(ok)
mini=min(mini,sum);
}
if(mini=INF)
cout<<-1;
else
cout<<mini;
return 0;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:39:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=0;i<s.size();++i)
| ~^~~~~~~~~
ho_t2.cpp:48:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int j=i+1;j<s.size();++j)
| ~^~~~~~~~~
ho_t2.cpp:76:12: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
76 | if(mini=INF)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |