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 pll pair<ll, ll>
#define pii pair<int, int>
#define vl vector<ll>
#define sl set<ll>
#define pb push_back
#define all(v) v.begin(), v.end()
#define f first
#define s second
#define ld long double
using namespace std;
int main()
{
int n, i, j, k, sz = INT_MAX, o;
string s;
cin >> n >> k;
cin >> s;
vector<int>J, O, I;
for(i = 0; i < n; i++)
{
if(s[i] == 'J') J.pb(i);
else if(s[i] == 'O') O.pb(i);
else I.pb(i);
}
for(j = k - 1; j < J.size(); j++)
{
o = upper_bound(all(O), J[j]) - O.begin();
if(o + k - 1 >= O.size()) continue;
o += (k - 1);
i = upper_bound(all(I), O[o]) - I.begin();
if(i + k - 1 >= I.size()) continue;
i += (k - 1);
sz = min(sz, I[i] - J[j-k+1]+1);
}
if(sz == INT_MAX) cout << "-1\n";
else cout << sz - k * 3 << "\n";
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(j = k - 1; j < J.size(); j++)
| ~~^~~~~~~~~~
ho_t2.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if(o + k - 1 >= O.size()) continue;
| ~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if(i + k - 1 >= 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... |