Submission #795262

#TimeUsernameProblemLanguageResultExecution timeMemory
795262Theo830JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
6 ms3288 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ll,ii> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n,k; cin>>n>>k; string s; cin>>s; vll ex[3]; ll p[3] = {0}; f(i,0,n){ if(s[i] == 'J'){ ex[0].pb(i); } else if(s[i] == 'O'){ ex[1].pb(i); } else{ ex[2].pb(i); } } ll ans = n+1; f(i,0,n){ while(p[0] < ex[0].size() && ex[0][p[0]] < i){ p[0]++; } if(p[0]+k-1 >= ex[0].size()){ break; } while(p[1] < ex[1].size() && ex[1][p[1]] < ex[0][p[0] + k - 1]){ p[1]++; } if(p[1]+k-1 >= ex[1].size()){ break; } while(p[2] < ex[2].size() && ex[2][p[2]] < ex[1][p[1] + k - 1]){ p[2]++; } if(p[2]+k-1 >= ex[2].size()){ break; } ans = min(ans,n - ex[0][p[0]] - (n-1 - ex[2][p[2] + k-1]) - 3 * k); } if(ans == n+1){ ans = -1; } cout<<ans<<"\n"; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:47:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         while(p[0] < ex[0].size() && ex[0][p[0]] < i){
      |               ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:50:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if(p[0]+k-1 >= ex[0].size()){
      |            ~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:53:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while(p[1] < ex[1].size() && ex[1][p[1]] < ex[0][p[0] + k - 1]){
      |               ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:56:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         if(p[1]+k-1 >= ex[1].size()){
      |            ~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:59:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         while(p[2] < ex[2].size() && ex[2][p[2]] < ex[1][p[1] + k - 1]){
      |               ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:62:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         if(p[2]+k-1 >= ex[2].size()){
      |            ~~~~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...