# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
669262 | GrandTiger1729 | JJOOII 2 (JOI20_ho_t2) | C++17 | 8 ms | 868 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 <iostream>
using namespace std;
int val(char c){
if (c == 'J') return 0;
if (c == 'O') return 1;
if (c == 'I') return 2;
}
const int INF = 1e9 + 9;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, k; cin >> n >> k;
string s; cin >> s;
int l[3]{}, r[3]{}, cnt[3]{};
int ans = INF;
while (true){
while (r[0] < n && cnt[0] < k){
if (val(s[r[0]++]) == 0)
cnt[0]++;
}
while (l[1] < r[0]){
if (val(s[l[1]++]) == 1)
cnt[1]--;
}
while (r[1] < n && cnt[1] < k){
if (val(s[r[1]++]) == 1)
cnt[1]++;
}
while (l[2] < r[1]){
if (val(s[l[2]++]) == 2)
cnt[2]--;
}
while (r[2] < n && cnt[2] < k){
if (val(s[r[2]++]) == 2)
cnt[2]++;
}
if (cnt[0] < k || cnt[1] < k || cnt[2] < k) break;
ans = min(ans, r[2] - l[0] - 3 * k);
if (val(s[l[0]++]) == 0)
cnt[0]--;
}
cout << (ans == INF? -1: ans);
return 0;
}
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... |