Submission #654748

#TimeUsernameProblemLanguageResultExecution timeMemory
654748inwbearJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
0 ms308 KiB
#include<bits/stdc++.h> using namespace std; vector<int>v[3]; int n,k; string s; int main(){ cin>>n>>k; cin>>s; for(int i=0;i<n;i++){ if(s[i]=='J'){ v[0].push_back(i); }else if(s[i]=='O'){ v[1].push_back(i); }else{ v[2].push_back(i); } } int x=-1; int min=INT_MAX; for(int i=k-1;i<v[0].size();i++){ int comp=v[0][i]; int st=0,en=v[1].size()-1; while(st<=en){ int mid=(st+en)/2; if(v[1][mid]>comp){ en=mid-1; x=mid; }else{ st=mid+1; } } if(x==-1){ break; } x+=k-1; if(x>v[1].size()){ break; } int y=0; comp=v[1][x]; st=0,en=v[2].size()-1; while(st<=en){ int mid=(st+en)/2; if(v[2][mid]>comp){ en=mid-1; x=mid; y=1; }else{ st=mid+1; } } if(y!=1){ break; } x+=k-1; if(x>v[2].size()){ break; } int ans=v[2][x]-(v[0][i-k+1])+1-3*k; if(ans<min){ //cout<<v[2][x]<<" "<<(v[0][i-k+1])<<endl; min=ans; } } if(min!=INT_MAX){ cout<<min; }else{ cout<<"-1"; } }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=k-1;i<v[0].size();i++){
      |                   ~^~~~~~~~~~~~
ho_t2.cpp:36:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if(x>v[1].size()){
      |            ~^~~~~~~~~~~~
ho_t2.cpp:56:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         if(x>v[2].size()){
      |            ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...