제출 #288813

#제출 시각아이디문제언어결과실행 시간메모리
288813Leonardo_PaesJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
8 ms1676 KiB
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    deque<int> J, O, I, aux;
    for(int i=0; i<n; i++){
        if(s[i] == 'J') J.push_back(i);
        else if(s[i] == 'O') O.push_back(i);
        else I.push_back(i);
    }
    int ans = 0x3f3f3f3f;
    for(int j=0, o=0; I.size() >= k and o+k <= O.size(); o++){
        int l = O[o], r = O[o+k-1];
        while(j<J.size() and J[j] < l) aux.push_back(J[j++]);
        while(aux.size() > k) aux.pop_front();
        while(!I.empty() and I.front() < r) I.pop_front();
        if(aux.size() == k and I.size() >= k) ans = min(ans, (I[k-1] - aux[0] + 1) - 3*k);
    }
    cout << (ans == 0x3f3f3f3f ? -1 : ans) << "\n";
    return 0;
}

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

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:16:32: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |     for(int j=0, o=0; I.size() >= k and o+k <= O.size(); o++){
      |                       ~~~~~~~~~^~~~
ho_t2.cpp:16:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int j=0, o=0; I.size() >= k and o+k <= O.size(); o++){
      |                                         ~~~~^~~~~~~~~~~
ho_t2.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         while(j<J.size() and J[j] < l) aux.push_back(J[j++]);
      |               ~^~~~~~~~~
ho_t2.cpp:19:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |         while(aux.size() > k) aux.pop_front();
      |               ~~~~~~~~~~~^~~
ho_t2.cpp:21:23: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         if(aux.size() == k and I.size() >= k) ans = min(ans, (I[k-1] - aux[0] + 1) - 3*k);
      |            ~~~~~~~~~~~^~~~
ho_t2.cpp:21:41: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         if(aux.size() == k and I.size() >= k) ans = min(ans, (I[k-1] - aux[0] + 1) - 3*k);
      |                                ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...