답안 #994363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
994363 2024-06-07T13:23:05 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;

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 = -1;
    for(int i = 0; i < jidxs.size()-k+1; i++) {
        int pos = 0;
        if(i+k-1>=jidxs.size()) {
            continue;
        }
        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+k-1>=oidxs.size()) {
            continue;
        }
        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+k-1>=iidxs.size()) {
            continue;
        }
        for(int 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(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:36:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if(i+k-1>=jidxs.size()) {
      |            ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:43:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         if(o_idx+k-1>=oidxs.size()) {
      |            ~~~~~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if(i_idx+k-1>=iidxs.size()) {
      |            ~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -