Submission #647311

#TimeUsernameProblemLanguageResultExecution timeMemory
647311ck_platypusJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
9 ms3120 KiB
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <bitset>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <queue>
#include <cstring>
#include <fstream>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define plpll pair<ll, pll>
#define pii pair<int, int>
#define f first
#define s second
#define inf 1000000000000000
#define endl '\n'
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> a[3];
    char in;
    for(int i=0;i<n;i++){
        cin >> in;
        if(in=='J') a[0].pb(i);
        else if(in=='O') a[1].pb(i);
        else a[2].pb(i);
    }
    if(a[0].size()<k){
        cout << "-1\n";
        return 0;
    }
    ll ol=0, il=0, ans=-1;
    for(int i=k-1;i<a[0].size();i++){
        while(a[1][ol]<a[0][i] && ol<a[1].size()) ol++;
        if(ol+k>a[1].size()) break;
        while(a[2][il]<a[1][ol+k-1]) il++;
        if(il+k>a[2].size()) break;
        //cout << i << " " << ol << " " << il << endl;
        if(ans==-1 || ans>a[2][il+k-1]-a[0][i-k+1]-k*3+1) ans=a[2][il+k-1]-a[0][i-k+1]-k*3+1;
    }
    cout << ans << endl;
    return 0;
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:38:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   38 |     if(a[0].size()<k){
      |        ~~~~~~~~~~~^~
ho_t2.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=k-1;i<a[0].size();i++){
      |                   ~^~~~~~~~~~~~
ho_t2.cpp:44:37: 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]
   44 |         while(a[1][ol]<a[0][i] && ol<a[1].size()) ol++;
      |                                   ~~^~~~~~~~~~~~
ho_t2.cpp:45: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]
   45 |         if(ol+k>a[1].size()) break;
      |            ~~~~^~~~~~~~~~~~
ho_t2.cpp:47: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]
   47 |         if(il+k>a[2].size()) break;
      |            ~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...