Submission #870615

#TimeUsernameProblemLanguageResultExecution timeMemory
870615Maite_MoraleJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
9 ms5604 KiB
#include<bits/stdc++.h> #define F first #define S second #define MAX 500005 #define oo 1e18 #define mod 1000000007 #define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0); using namespace std; typedef long long ll; #define pll pair<ll , ll> #define vll vector<ll> #define vvll vector<vll> #define vpll vector<pll> ll n,k; string a; map<char,ll> mp; vll v[5];ll d[MAX]; int main(){ cin>>n>>k>>a;mp['J']=1;mp['O']=2;mp['I']=3; for(int i=0;i<n;i++){ d[i]=v[mp[a[i]]].size(); v[mp[a[i]]].push_back(i); }ll op=0,ip=0;ll ans=oo; for(int i=0;i<=v[1].size()-k;i++){ op=max(op,v[1][i+k-1]+1); while(op<n-1 && a[op]!='O')op++; if(op==n || a[op]!='O')break; if(d[op]+k-1>=v[2].size())break; ip=max(ip,v[2][d[op]+k-1]+1); while(ip<n-1 && a[ip]!='I')ip++; if(ip==n || a[ip]!='I')break; if(d[ip]+k-1>=v[3].size())break; ans=min(ans,v[3][d[ip]+k-1]-v[1][i]+1-3*k); }if(ans==oo)ans=-1; cout<<ans; return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   25 |     for(int i=0;i<=v[1].size()-k;i++){
      |                 ~^~~~~~~~~~~~~~~
ho_t2.cpp:29: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]
   29 |         if(d[op]+k-1>=v[2].size())break;
      |            ~~~~~~~~~^~~~~~~~~~~~~
ho_t2.cpp:33: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]
   33 |         if(d[ip]+k-1>=v[3].size())break;
      |            ~~~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...