Submission #672107

#TimeUsernameProblemLanguageResultExecution timeMemory
672107sofija6JJOOII 2 (JOI20_ho_t2)C++14
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> #define ll long long #define MAXN 200010 #define llinf 1000000000 using namespace std; vector<ll> posj,poso,posi,mino,mini; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n,k; string s; cin >> n >> k >> s; for (ll i=0;i<n;i++) { if (s[i]=='J') posj.push_back(i); else if (s[i]=='O') poso.push_back(i); else posi.push_back(i); } mino.resize(poso.size()+1,llinf); mini.resize(posi.size()+1,llinf); for (ll i=posi.size()-1;i>=0;i--) { if (i+k-1>=posi.size()) continue; if (i+1<posi.size()) mini[i]=min(mini[i+1]+posi[i+1]-posi[i],posi[i+k-1]-posi[i]-k+1); else mini[i]=posi[i+k-1]-posi[i]-k+1; } for (ll i=poso.size()-1;i>=0;i--) { if (i+k-1>=poso.size()) continue; auto it=lower_bound(posi.begin(),posi.end(),poso[i+k-1]); if (it==posi.end()) continue; if (i+1<poso.size()) mino[i]=min(mino[i+1]+poso[i+1]-poso[i],poso[i+k-1]-poso[i]-k+mini[it-posi.begin()]+posi[it-posi.begin()]-poso[i+k-1]); else mino[i]=poso[i+k-1]-poso[i]-k+mini[it-posi.begin()]+posi[it-posi.begin()]-poso[i+k-1]; } ll ans=llinf; for (ll i=0;i+k-1<posj.size();i++) { auto it=lower_bound(poso.begin(),poso.end(),posj[i+k-1]); if (it==poso.end()) break; if (i+1<posj.size()) ans=min(ans,posj[i+k-1]-posj[i]-k+mino[it-poso.begin()]+poso[it-poso.begin()]-posj[i+k-1]); else ans=posj[i+k-1]-posj[i]-k+mino[it-poso.begin()]+poso[it-poso.begin()]-posj[i+k-1]; } cout << (ans>=llinf?-1 : ans); return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:26: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]
   26 |         if (i+k-1>=posi.size())
      |             ~~~~~^~~~~~~~~~~~~
ho_t2.cpp:28:16: 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]
   28 |         if (i+1<posi.size())
      |             ~~~^~~~~~~~~~~~
ho_t2.cpp:35: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]
   35 |         if (i+k-1>=poso.size())
      |             ~~~~~^~~~~~~~~~~~~
ho_t2.cpp:40:16: 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]
   40 |         if (i+1<poso.size())
      |             ~~~^~~~~~~~~~~~
ho_t2.cpp:46:22: 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]
   46 |     for (ll i=0;i+k-1<posj.size();i++)
      |                 ~~~~~^~~~~~~~~~~~
ho_t2.cpp:51:16: 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]
   51 |         if (i+1<posj.size())
      |             ~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...