제출 #974083

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


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n,k; cin>>n>>k;
    string s;cin>>s;

    int prefj[n],prefo[n],prefi[n];
    for(int i=0;i<n;i++){
      prefj[i]=n+1;
      prefo[i]=n+1;
      prefi[i]=n+1;
    }
    queue<int> posj,poso,posi;
    for(int i=n-1;i>=0;i--){
      if(s[i]=='J') posj.push(i);
      if(s[i]=='O') poso.push(i);
      if(s[i]=='I') posi.push(i);
      while (posj.size()>k) posj.pop();
      if (posj.size()==k) prefj[i]=posj.front();
      while (poso.size()>k) poso.pop();
      if (poso.size()==k) prefo[i]=poso.front();
      while (posi.size()>k) posi.pop();
      if (posi.size()==k) prefi[i]=posi.front();
    }
    int ans=n+1;
    for (int i=0;i<n;i++) {
      if (prefj[i]+1>=n) continue;
      if (prefo[prefj[i]+1]+1>=n) continue;
      if (prefi[prefo[prefj[i]+1]+1]>=n) continue;
      ans=min(ans,prefi[prefo[prefj[i]+1]+1]-i+1-3*k);
    }
    if(ans==(n+1)) cout<<-1;
    else cout<<ans;

}

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

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:24:25: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |       while (posj.size()>k) posj.pop();
      |              ~~~~~~~~~~~^~
ho_t2.cpp:25:22: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |       if (posj.size()==k) prefj[i]=posj.front();
      |           ~~~~~~~~~~~^~~
ho_t2.cpp:26:25: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |       while (poso.size()>k) poso.pop();
      |              ~~~~~~~~~~~^~
ho_t2.cpp:27:22: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |       if (poso.size()==k) prefo[i]=poso.front();
      |           ~~~~~~~~~~~^~~
ho_t2.cpp:28:25: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |       while (posi.size()>k) posi.pop();
      |              ~~~~~~~~~~~^~
ho_t2.cpp:29:22: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |       if (posi.size()==k) prefi[i]=posi.front();
      |           ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...