Submission #994341

# Submission time Handle Problem Language Result Execution time Memory
994341 2024-06-07T12:25:00 Z rsinventor JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 344 KB
//
//  main.cpp
//  jjooii_2
//
//  Created by Raunak Singh on 6/7/24.
//

#include "bits/stdc++.h"
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> jidxs;
    vector<int> oidxs;
    vector<int> iidxs;
    for(int i = 0; i < n; i++) {
        if(s[i]=='J') {
            jidxs.push_back(i);
        } else if(s[i]=='O') {
            oidxs.push_back(i);
        } else if(s[i]=='I') {
            iidxs.push_back(i);
        }
    }
    if(jidxs.size()<k || iidxs.size()<k || oidxs.size()<k) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 1e6;
    for(int i = 0; i < jidxs.size()-k+1; i++) {
        int pos = 0;
        for(int j = i; j < i+k-1; j++) {
            pos += jidxs[j+1] - jidxs[j] - 1;
        }
        int o_idx = lower_bound(oidxs.begin(), oidxs.end(), jidxs[i+k-1]) - oidxs.begin();
        if(o_idx>=oidxs.size()) {
            cout << -1 << endl;
            return 0;
        }
        for(int j = o_idx; j < o_idx+k-1; j++) {
            pos += oidxs[j+1] - oidxs[j] - 1;
        }
        int i_idx = lower_bound(iidxs.begin(), iidxs.end(), oidxs[o_idx+k-1]) - iidxs.begin();
        if(i_idx>=iidxs.size()) {
            cout << -1 << endl;
            return 0;
        }
        for(int j = i_idx; j < i_idx + k -1; j++) {
            pos += iidxs[j+1] - iidxs[j] - 1;
        }
        ans = min(ans, pos);
    }
    cout << ans << endl;
    

    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main(int, const char**)':
ho_t2.cpp:29:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     if(jidxs.size()<k || iidxs.size()<k || oidxs.size()<k) {
      |        ~~~~~~~~~~~~^~
ho_t2.cpp:29:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     if(jidxs.size()<k || iidxs.size()<k || oidxs.size()<k) {
      |                          ~~~~~~~~~~~~^~
ho_t2.cpp:29:56: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     if(jidxs.size()<k || iidxs.size()<k || oidxs.size()<k) {
      |                                            ~~~~~~~~~~~~^~
ho_t2.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0; i < jidxs.size()-k+1; i++) {
      |                    ~~^~~~~~~~~~~~~~~~~~
ho_t2.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if(o_idx>=oidxs.size()) {
      |            ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:48:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         if(i_idx>=iidxs.size()) {
      |            ~~~~~^~~~~~~~~~~~~~
# 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 -