Submission #838010

#TimeUsernameProblemLanguageResultExecution timeMemory
838010vjudge1JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
5 ms3032 KiB
#include <bits/stdc++.h>
using namespace std;
#define int     long long
#define ll      long long
#define pii     pair <int, int> 
#define pb      push_back
#define mp      make_pair
#define dbg     puts("dbg");
#define outp(x) cout << #x << " = " << (x) << endl

int n, k, indeksJ, indeksO, indeksI, mini = 1e9;
string S;
vector <int> J, O, I;

void solve(){   
    cin >> n >> k;
    cin >> S;
    for(int i=0; i<S.length(); i++){
        if(S[i] == 'J') J.pb(i);
        else if(S[i] == 'O') O.pb(i);
        else I.pb(i);
    }
    while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
        int awalJ, awalO, awalI;
        int akhirJ, akhirO, akhirI;
        if(indeksJ+k-1 >= J.size()) break;
        awalJ = J[indeksJ];
        akhirJ = J[indeksJ+k-1];
        while(O[indeksO] < akhirJ) indeksO++;
        if(indeksO+k-1 >= O.size()) break;
        awalO = O[indeksO];
        akhirO = O[indeksO+k-1];
        while(I[indeksI] < akhirO) indeksI++;
        if(indeksI+k-1 >= I.size()) break;
        awalI = I[indeksI];
        akhirI = I[indeksI+k-1];
        int hapus = akhirI - awalJ + 1 - 3*k;
        mini = min(mini, hapus);
        indeksJ++;
    }
    cout << ((mini != 1e9)?mini:-1) << endl;
}


int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    solve();
    return 0;
}

Compilation message (stderr)

ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:18:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0; i<S.length(); i++){
      |                  ~^~~~~~~~~~~
ho_t2.cpp:23:19: 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]
   23 |     while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
      |           ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:23:41: 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]
   23 |     while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
      |                                 ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:23:63: 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]
   23 |     while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
      |                                                       ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:26:24: 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(indeksJ+k-1 >= J.size()) break;
      |            ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:30:24: 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]
   30 |         if(indeksO+k-1 >= O.size()) break;
      |            ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:34:24: 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]
   34 |         if(indeksI+k-1 >= I.size()) break;
      |            ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:24:20: warning: variable 'awalO' set but not used [-Wunused-but-set-variable]
   24 |         int awalJ, awalO, awalI;
      |                    ^~~~~
ho_t2.cpp:24:27: warning: variable 'awalI' set but not used [-Wunused-but-set-variable]
   24 |         int awalJ, awalO, awalI;
      |                           ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...