답안 #774441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774441 2023-07-05T18:01:37 Z stefanneagu JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 212 KB
#include <iostream>
#include <vector>
using namespace std; 
int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> J, O, I;
    for(int i = 0; i < n; i ++) {
        if(s[i] == 'J') {
            J.push_back(i);
        }
        if(s[i] == 'O') {
            O.push_back(i);
        }
        if(s[i] == 'I') {
            I.push_back(i);
        } 
    }
    int ans = 1e9;
    for(int i = 0; i < J.size() - k + 1; i ++) {
        int pos_o = lower_bound(O.begin(), O.end(), J[i + k - 1]) - O.begin();
        if(pos_o <= O.size() - k + 1) {
            int pos_i = lower_bound(I.begin(), I.end(), O[pos_o + k - 1]) - I.begin();
            if(pos_i <= I.size() - k + 1) {
                int term = I[pos_i + k - 1];
                ans = min(ans, term - i - 3 * k);
            }
        }
    }
    cout << ans;
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < J.size() - k + 1; i ++) {
      |                    ~~^~~~~~~~~~~~~~~~~~
ho_t2.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         if(pos_o <= O.size() - k + 1) {
      |            ~~~~~~^~~~~~~~~~~~~~~~~~~
ho_t2.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             if(pos_i <= I.size() - k + 1) {
      |                ~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -