# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1023704 | vjudge1 | JJOOII 2 (JOI20_ho_t2) | C++17 | 1 ms | 348 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>
#include <string>
using namespace std;
int min_operations_to_form_JOI_string(int N, int K, const string& S) {
if (K > N / 3) return -1;
int required_count = K * 3;
int count_J = 0, count_O = 0, count_I = 0;
int left = 0, right = N - 1;
while (left <= right) {
if (count_J < K && S[left] == 'J') {
count_J++;
left++;
} else if (count_I < K && S[right] == 'I') {
count_I++;
right--;
} else if (count_O < K && S[left] == 'O') {
count_O++;
left++;
} else {
left++;
right--;
}
}
int remaining_operations = 0;
if (count_J < K) remaining_operations += K - count_J;
if (count_O < K) remaining_operations += K - count_O;
if (count_I < K) remaining_operations += K - count_I;
return remaining_operations;
}
int main() {
int N, K;
string S;
cin >> N >> K >> S;
int result = min_operations_to_form_JOI_string(N, K, S);
cout << result << endl;
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... |