Submission #207832

#TimeUsernameProblemLanguageResultExecution timeMemory
207832kai824JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
16 ms1916 KiB
#include "bits/stdc++.h" using namespace std; vector<int> js,os,is;//store indexes... int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,k,b1,b2,b3,ans=INT_MAX; string s; cin>>n>>k>>s; for(int i=0;i<n;i++){ if(s[i]=='J')js.push_back(i); else if(s[i]=='O')os.push_back(i); else is.push_back(i); } for(int i=k-1;i<is.size();i++){//must contain at least k of each kind... b1=is[i-(k-1)];//first break point... b1=(lower_bound(os.begin(),os.end(),b1)-os.begin()) -k;//index in os... if(b1<0)continue; b2=os[b1]; b2=(lower_bound(js.begin(),js.end(),b2)-js.begin()) -k;//index in js... if(b2<0)continue; b2=js[b2]; ans=min(is[i]-b2+1,ans); } if(ans==INT_MAX)cout<<"-1\n"; else cout<<ans-(k*3)<<'\n'; return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=k-1;i<is.size();i++){//must contain at least k of each kind...
                   ~^~~~~~~~~~
ho_t2.cpp:8:19: warning: unused variable 'b3' [-Wunused-variable]
     int n,k,b1,b2,b3,ans=INT_MAX;
                   ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...