Submission #994364

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

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

int main() {
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<ll> jidxs;
    vector<ll> oidxs;
    vector<ll> iidxs;
    for(ll 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;
    }
    ll ans = -1;
    for(ll i = 0; i < jidxs.size()-k+1; i++) {
        ll pos = 0;
        for(ll j = i; j < i+k-1; j++) {
            pos += jidxs[j+1] - jidxs[j] - 1;
        }
        ll o_idx = lower_bound(oidxs.begin(), oidxs.end(), jidxs[i+k-1]) - oidxs.begin();
        if(o_idx+k-1>=oidxs.size()) {
            continue;
        }
        for(ll j = o_idx; j < o_idx+k-1; j++) {
            pos += oidxs[j+1] - oidxs[j] - 1;
        }
        ll i_idx = lower_bound(iidxs.begin(), iidxs.end(), oidxs[o_idx+k-1]) - iidxs.begin();
        if(i_idx+k-1>=iidxs.size()) {
            continue;
        }
        for(ll j = i_idx; j < i_idx + k -1; j++) {
            pos += iidxs[j+1] - iidxs[j] - 1;
        }
        if(ans==-1 || pos < ans) {
            ans = pos;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:29:20: 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]
   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<long long int>::size_type' {aka 'long unsigned int'} and 'long long 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<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   29 |     if(jidxs.size()<k || iidxs.size()<k || oidxs.size()<k) {
      |                                            ~~~~~~~~~~~~^~
ho_t2.cpp:34:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   34 |     for(ll i = 0; i < jidxs.size()-k+1; i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~
ho_t2.cpp:40:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if(o_idx+k-1>=oidxs.size()) {
      |            ~~~~~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:47:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if(i_idx+k-1>=iidxs.size()) {
      |            ~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 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 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -