# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
583844 | MODDI | JJOOII 2 (JOI20_ho_t2) | C++14 | 1 ms | 212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
int n, k;
string str;
int main(){
cin>>n>>k>>str;
string cpy;
int l = 0, r = n-1;
while(str[l] == 'O' || str[l] == 'I')
l++;
while(str[r] == 'J' || str[r] == 'O')
r--;
if(l > r)
{
cout<<-1<<endl;
return 0;
}
for(int i = l; i <= r; i++)
cpy.pb(str[i]);
str = cpy;
int rez = 0, j = 0;
string target;
for(int i = 0; i < k; i++)
target.pb('J');
for(int i = 0; i < k; i++)
target.pb('O');
for(int i = 0; i < k; i++)
target.pb('I');
for(int i = 0; i < str.size(); i++){
if(str[i] == target[j]){
j++;
continue;
}
else{
rez++;
}
}
cout<<rez<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |