# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201408 | karma | JJOOII 2 (JOI20_ho_t2) | C++14 | 16 ms | 2948 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 emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
//#define int int64_t
using namespace std;
const int N = int(2e5) + 5;
typedef pair<int, int> pii;
string s;
int n, k, jump[N][3], cnt;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define Task "test"
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n >> k >> s;
for(int i = 0, j = -1; i < n; ++i) {
while(cnt < k && j + 1 < n) {
++j;
if(s[j] == 'J') ++cnt;
}
if(cnt >= k) jump[i][0] = j;
else jump[i][0] = n + n;
if(s[i] == 'J') --cnt;
} cnt = 0;
for(int i = 0, j = -1; i < n; ++i) {
while(cnt < k && j + 1 < n) {
++j;
if(s[j] == 'O') ++cnt;
}
if(cnt >= k) jump[i][1] = j;
else jump[i][1] = n + n;
if(s[i] == 'O') --cnt;
} cnt = 0;
for(int i = 0, j = -1; i < n; ++i) {
while(cnt < k && j + 1 < n) {
++j;
if(s[j] == 'I') ++cnt;
}
if(cnt >= k) jump[i][2] = j;
else jump[i][2] = n + n;
if(s[i] == 'I') --cnt;
}
int ans = n + n;
for(int i = 0, j; i < n; ++i) {
j = jump[i][0];
if(j >= n) continue;
j = jump[j][1];
if(j >= n) continue;
j = jump[j][2];
if(j >= n) continue;
ans = min(ans, j - i + 1 - k * 3);
}
if(ans == n + n) ans = -1;
cout << ans;
}
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... |