# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
206213 | combi1k1 | JJOOII 2 (JOI20_ho_t2) | C++14 | 76 ms | 3012 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>
using namespace std;
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pb emplace_back
#define endl "\n"
const ll inf = 1e18;
const int N = 2e5 + 5;
typedef pair<int,int> ii;
int c[N][3];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k; cin >> n >> k;
string S; cin >> S;
S = "#" + S;
for(int i = 1 ; i <= n ; ++i) {
c[i][0] = c[i - 1][0] + (S[i] == 'J');
c[i][1] = c[i - 1][1] + (S[i] == 'O');
c[i][2] = c[i - 1][2] + (S[i] == 'I');
}
int ans = 1e9 + 7;
for(int i = 1 ; i <= n ; ++i) {
int p = i;
for(int j = 0 ; j < 3 ; ++j) {
int l = p;
int r = n + 1;
while (l < r) {
int m = l + r >> 1;
if (c[m][j] - c[p - 1][j] >= k)
r = m;
else
l = m + 1;
}
p = l;
}
if (p <= n)
ans = min(ans,p + 1 - 3 * k - i);
}
if (ans == 1e9 + 7)
ans = -1;
cout << ans << 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... |