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>
using namespace std;
using ll = long long;
ll N, K;
string S;
vector<ll> J, O, I;
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N >> K >> S;
S = " " + S;
for(ll i = 1; i <= N; i++){
if(S[i] == 'J') J.push_back(i);
if(S[i] == 'O') O.push_back(i);
if(S[i] == 'I') I.push_back(i);
}
ll t = 1e18;
for(ll i = 1; i <= N; i++){
ll p = lower_bound(J.begin(), J.end(), i) - J.begin() + K - 1;
if(p >= J.size()) continue;
ll q = lower_bound(O.begin(), O.end(), J[p]) - O.begin() + K - 1;
if(q >= O.size()) continue;
ll r = lower_bound(I.begin(), I.end(), O[q]) - I.begin() + K - 1;
if(r >= I.size()) continue;
t = min(t, I[r] - i + 1 - 3 * K);
}
cout << (t == 1e18 ? -1 : t);
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:22:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if(p >= J.size()) continue;
| ~~^~~~~~~~~~~
ho_t2.cpp:25:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if(q >= O.size()) continue;
| ~~^~~~~~~~~~~
ho_t2.cpp:28:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(r >= I.size()) continue;
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |