제출 #1115770

#제출 시각아이디문제언어결과실행 시간메모리
1115770staszic_ojuzJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
8 ms4556 KiB
#include <bits/stdc++.h>
using namespace std;

int n, k, J[200001], O[200001], I[200001];
vector<int> J_gdzie, O_gdzie, I_gdzie;
string word;



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    cin >> word;
    if(word[0] == 'J'){
        J_gdzie.push_back(0);
        J[0]++;
    }
    if(word[0] == 'O'){
        O_gdzie.push_back(0);
        O[0]++;
    }
    if(word[0] == 'I'){
        I_gdzie.push_back(0);
        I[0]++;
    }

    for(int i = 1; i < n; i++){
        //cout << J[i] << " " << I[i] << " " << O[i] << " " << word[i] << endl;
        J[i] = J[i - 1];
        O[i] = O[i - 1];
        I[i] = I[i - 1];
        if(word[i] == 'J'){
            J_gdzie.push_back(i);
            J[i]++;
        }
        if(word[i] == 'O'){
            O_gdzie.push_back(i);
            O[i]++;
        }
        if(word[i] == 'I'){
            I_gdzie.push_back(i);
            I[i]++;
        }
    }
    for(int i = 0; i < n; i++){
        //cout << J[i] << " " << O[i] << " " << I[i] << endl;
    }
    int wynik = 200001;
    for(int i = 0; i < J_gdzie.size(); i++){
        int ind_j = J_gdzie[i];
        if(J_gdzie.size() - J[ind_j] + 2 > k){
            int ind_o = J_gdzie[J[ind_j] + k - 2];
            if(O_gdzie.size() - O[ind_o] + 1 > k){
                int ind_i = O_gdzie[O[ind_o] + k - 1];
                if(I_gdzie.size() - I[ind_i] + 1 > k){
                    wynik = min(wynik, I_gdzie[I[ind_i] + k - 1] - ind_j + 1 - 3 * k);
                }
            }
        }
    }
    if(wynik == 200001){
        wynik = -1;
    }
    cout << wynik;
}

컴파일 시 표준 에러 (stderr) 메시지

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i = 0; i < J_gdzie.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
ho_t2.cpp:52:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |         if(J_gdzie.size() - J[ind_j] + 2 > k){
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
ho_t2.cpp:54:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |             if(O_gdzie.size() - O[ind_o] + 1 > k){
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
ho_t2.cpp:56:50: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |                 if(I_gdzie.size() - I[ind_i] + 1 > k){
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...