Submission #997143

#TimeUsernameProblemLanguageResultExecution timeMemory
997143giorgi_pkhaladzeJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #define pb push_back #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define ff first #define ss second using namespace std; vector <int> j,o,i; int n,m,k,ans,a[200001],ph[200001],sh[200001]; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>m; cin>>s; s=' '+s; if(m*3>n){ cout<<-1; return 0; } for(k=1; k<=n; k++){ ph[k]=ph[k-1]; if(s[k]=='J')ph[k]++,j.pb(k); if(s[k]=='I')i.pb(k); if(s[k]=='O')o.pb(k); } for(k=n; k>0; k--){ sh[k]=sh[k+1]; if(s[k]=='I')sh[k]++; } if(j.size()<m && o.size()<m && i.size()<n) { cout<<-1; return 0; } //cout<<"GIO"; return 0; int ans=10000; for(k=0; k<=o.size()-m; k++){ //cout<<sh[o[k]]<<" "<<ph[o[k]]<<'\n'; if(sh[o[k]]<m)break; if(ph[o[k]]>m)break; int pos1=lower_bound(j.begin(),j.end(),o[k])-1-j.begin(); int pos2=lower_bound(i.begin(),i.end(),o[k+m-1])-i.begin(); int sz=j[pos1]-j[pos1-m+1]-m; if(pos1<m-1 || pos2>(int)i.size()-m)continue; //cout<<pos1+1<<" "<<pos2+1<<'\n'; sz++; //cout<<sz<<'\n'; sz+=i[pos2+m-1]-i[pos2]-m+1; //cout<<sz<<'\n'; sz+=o[k+m-1]-o[k]-m+1; //ans=min(ans,sz); //cout<<ans<<'\n'; ans=min(ans,i[pos2+m-1]-j[1+pos1-m]+1-3*m); } if(ans==10000)cout<<-1; else cout<<ans; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:33:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |  if(j.size()<m && o.size()<m && i.size()<n)
      |     ~~~~~~~~^~
ho_t2.cpp:33:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |  if(j.size()<m && o.size()<m && i.size()<n)
      |                   ~~~~~~~~^~
ho_t2.cpp:33:41: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |  if(j.size()<m && o.size()<m && i.size()<n)
      |                                 ~~~~~~~~^~
ho_t2.cpp:40:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for(k=0; k<=o.size()-m; k++){
      |           ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...