#include <bits/stdc++.h>
#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:24: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]
24 | for(int i=0;i<s.size();++i)
| ~^~~~~~~~~
ho_t2.cpp:33: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]
33 | for(int j=i+1;j<s.size();++j)
| ~^~~~~~~~~
ho_t2.cpp:61:12: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
61 | if(mini=INF)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |