Submission #745748

#TimeUsernameProblemLanguageResultExecution timeMemory
745748owoovoJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
10 ms2032 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; int n,k; string s; vector<int> j,o,x; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>k>>s; int ans=n; for(int i=0;i<s.size();i++){ if(s[i]=='J')j.push_back(i); else if(s[i]=='O')o.push_back(i); else x.push_back(i); } for(int i=0;i+k<=j.size();i++){ int now=j[i+k-1]; now=lower_bound(o.begin(),o.end(),now)-o.begin(); if(now+k>o.size())break; now=o[now+k-1]; now=lower_bound(x.begin(),x.end(),now)-x.begin(); if(now+k>x.size())break; now=x[now+k-1]; ans=min(now-j[i]+1-k*3,ans); } if(ans==n){ cout<<"-1\n"; }else{ cout<<ans<<"\n"; } return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
ho_t2.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0;i+k<=j.size();i++){
      |                 ~~~^~~~~~~~~~
ho_t2.cpp:20:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         if(now+k>o.size())break;
      |            ~~~~~^~~~~~~~~
ho_t2.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         if(now+k>x.size())break;
      |            ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...