Submission #959797

#TimeUsernameProblemLanguageResultExecution timeMemory
959797happy_nodeJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
8 ms2268 KiB
#include <bits/stdc++.h> using namespace std; const int MX=2e5+5; int N,K; string s; vector<int> pos[3]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin>>N>>K; cin>>s; for(int i=0;i<N;i++) { if(s[i]=='J') pos[0].push_back(i); if(s[i]=='O') pos[1].push_back(i); if(s[i]=='I') pos[2].push_back(i); } int ans=2e9; for(int i=0;i+K-1<pos[1].size();i++) { int p=pos[1][i+K-1]; auto it=upper_bound(pos[2].begin(),pos[2].end(),p)-pos[2].begin(); if(it+K-1>=pos[2].size()) continue; auto it2=lower_bound(pos[0].begin(),pos[0].end(),pos[1][i])-pos[0].begin(); if(it2==0) continue; it2--; if(it2-K+1<0) continue; ans=min(ans,pos[2][it+K-1]-pos[0][it2-K+1]+1-3*K); } if(ans==2e9) { cout<<-1<<'\n'; return 0; } cout<<ans<<'\n'; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i=0;i+K-1<pos[1].size();i++) {
      |              ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:26:12: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   if(it+K-1>=pos[2].size()) continue;
      |      ~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...