답안 #1023703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023703 2024-07-15T05:04:28 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 348 KB
#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

ho_t2.cpp: In function 'int min_operations_to_form_JOI_string(int, int, const string&)':
ho_t2.cpp:6:9: warning: unused variable 'required_count' [-Wunused-variable]
    6 |     int required_count = K * 3;
      |         ^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -