Submission #1033314

# Submission time Handle Problem Language Result Execution time Memory
1033314 2024-07-24T16:25:07 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

void solve() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    if (n < 3 * k) {
        cout << -1 << '\n';
        return;
    }

    vector<int> j_idx, o_idx, i_idx;

    for (int i = 0; i < n; ++i) {
        if (s[i] == 'J') j_idx.push_back(i);
        else if (s[i] == 'O') o_idx.push_back(i);
        else if (s[i] == 'I') i_idx.push_back(i);
    }

    if (j_idx.size() < k || o_idx.size() < k || i_idx.size() < k) {
        cout << -1 << '\n';
        return;
    }

    int min_operations = LLONG_MAX;

    for (int i = 0; i <= j_idx.size() - k; ++i) {
        int j_start = j_idx[i];
        int j_end = j_idx[i + k - 1];

        for (int j = 0; j <= o_idx.size() - k; ++j) {
            int o_start = o_idx[j];
            int o_end = o_idx[j + k - 1];

            if (o_start < j_end) continue;

            for (int l = 0; l <= i_idx.size() - k; ++l) {
                int i_start = i_idx[l];
                int i_end = i_idx[l + k - 1];

                if (i_start < o_end) continue;

                int max_start = min({j_start, o_start, i_start});
                int min_end = max({j_end, o_end, i_end});
                int total_operations = (max_start - 0) + (n - 1 - min_end);

                min_operations = min(min_operations, total_operations);
            }
        }
    }

    if (min_operations == LLONG_MAX) {
        cout << -1 << '\n';
    } else {
        cout << min_operations << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
    return 0;
}

Compilation message

ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:25:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   25 |     if (j_idx.size() < k || o_idx.size() < k || i_idx.size() < k) {
      |         ~~~~~~~~~~~~~^~~
ho_t2.cpp:25:42: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   25 |     if (j_idx.size() < k || o_idx.size() < k || i_idx.size() < k) {
      |                             ~~~~~~~~~~~~~^~~
ho_t2.cpp:25:62: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   25 |     if (j_idx.size() < k || o_idx.size() < k || i_idx.size() < k) {
      |                                                 ~~~~~~~~~~~~~^~~
ho_t2.cpp:32:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   32 |     for (int i = 0; i <= j_idx.size() - k; ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~~~
ho_t2.cpp:36:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   36 |         for (int j = 0; j <= o_idx.size() - k; ++j) {
      |                         ~~^~~~~~~~~~~~~~~~~~~
ho_t2.cpp:42:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   42 |             for (int l = 0; l <= i_idx.size() - k; ++l) {
      |                             ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -