# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
484698 | Jarif_Rahman | JJOOII 2 (JOI20_ho_t2) | C++17 | 12 ms | 2016 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 pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int inf = 1e9;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k; str s; cin >> n >> k >> s;
vector<int> J, O, I;
for(int i = 0; i < n; i++){
if(s[i] == 'J') J.pb(i);
if(s[i] == 'O') O.pb(i);
if(s[i] == 'I') I.pb(i);
}
int ans = inf;
for(int i = k-1; i < O.size(); i++){
int cur = n;
cur-=3*k;
auto it = lower_bound(J.begin(), J.end(), O[i-k+1]);
int j = it-J.begin();
j--;
j-=k-1;
if(j < 0) continue;
cur-=J[j];
it = lower_bound(I.begin(), I.end(), O[i]);
if(it == I.end()) continue;
j = it-I.begin();
j+=k-1;
if(j >= I.size()) continue;
cur-=n-I[j]-1;
ans = min(ans, cur);
}
if(ans == inf) ans = -1;
cout << ans << "\n";
}
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... |