Submission #927675

#TimeUsernameProblemLanguageResultExecution timeMemory
927675AiperiiiJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
16 ms6568 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define all(x) x.begin(),x.end() #define pb push_back using namespace std; signed main(){ int n,k; cin>>n>>k; string s;cin>>s; s=' '+s; vector <int> v1,v2,v3; for(int i=1;i<s.size();i++){ if(s[i]=='J')v1.pb(i); else if(s[i]=='O')v2.pb(i); else v3.pb(i); } vector <pair <int,int> > g1,g3; for(int i=0;i<v1.size();i++){ if(i+k-1<v1.size()){ g1.pb({v1[i+k-1],v1[i]}); } } for(int i=0;i<v3.size();i++){ if(i+k-1<v3.size()){ g3.pb({v3[i],v3[i+k-1]}); } } vector <int> ans(v2.size(),-1); int mn=1e9; for(int i=0;i<v2.size();i++){ if(i+k-1<v2.size()){ pair <int,int> p={v2[i],0}; auto it=lower_bound(all(g1),p); if(it!=g1.begin() && g1.size()!=0){ it--; int ans=v2[i+k-1]-it->ss+1; p={v2[i+k-1],0}; it=lower_bound(all(g3),p); if(it!=g3.end()){ ans+=it->ss-v2[i+k-1]; mn=min(mn,ans-3*k); } } } } if(mn==1e9)mn=-1; cout<<mn<<"\n"; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:14:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i=1;i<s.size();i++){
      |                 ~^~~~~~~~~
ho_t2.cpp:20:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0;i<v1.size();i++){
      |                 ~^~~~~~~~~~
ho_t2.cpp:21:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         if(i+k-1<v1.size()){
      |            ~~~~~^~~~~~~~~~
ho_t2.cpp:25:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=0;i<v3.size();i++){
      |                 ~^~~~~~~~~~
ho_t2.cpp:26:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if(i+k-1<v3.size()){
      |            ~~~~~^~~~~~~~~~
ho_t2.cpp:32:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i=0;i<v2.size();i++){
      |                 ~^~~~~~~~~~
ho_t2.cpp:33:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if(i+k-1<v2.size()){
      |            ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...