Submission #1023602

# Submission time Handle Problem Language Result Execution time Memory
1023602 2024-07-15T03:35:17 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 348 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int main() {
    int N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    int requiredJ = K, requiredO = K, requiredI = K;
    int countJ = 0, countO = 0, countI = 0;
    vector<int> J(N+1, 0), O(N+1, 0), I(N+1, 0);
    for (int i = 0; i < N; ++i) {
        J[i+1] = J[i] + (S[i] == 'J');
        O[i+1] = O[i] + (S[i] == 'O');
        I[i+1] = I[i] + (S[i] == 'I');
    }
    int minOperations = INT_MAX;
    for (int start = 0; start <= N - 3*K; ++start) {
        int end = start + 3*K;
        int jCount = J[start + K] - J[start];
        int oCount = O[start + 2*K] - O[start + K];
        int iCount = I[end] - I[start + 2*K];
        if (jCount >= requiredJ && oCount >= requiredO && iCount >= requiredI) {
            int excessJ = J[start] + (J[N] - J[start + K]);
            int excessO = O[start + K] + (O[N] - O[start + 2*K]);
            int excessI = I[start + 2*K] + (I[N] - I[end]);
            int operations = N - 3*K - (excessJ + excessO + excessI);
            minOperations = min(minOperations, operations);
        }
    }
    if (minOperations == INT_MAX) {
        cout<<-1<<endl;
    } else {
        cout<<minOperations<<endl;
    }
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:12:9: warning: unused variable 'countJ' [-Wunused-variable]
   12 |     int countJ = 0, countO = 0, countI = 0;
      |         ^~~~~~
ho_t2.cpp:12:21: warning: unused variable 'countO' [-Wunused-variable]
   12 |     int countJ = 0, countO = 0, countI = 0;
      |                     ^~~~~~
ho_t2.cpp:12:33: warning: unused variable 'countI' [-Wunused-variable]
   12 |     int countJ = 0, countO = 0, countI = 0;
      |                                 ^~~~~~
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -