Submission #838010

# Submission time Handle Problem Language Result Execution time Memory
838010 2023-08-26T04:22:02 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
5 ms 3032 KB
#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

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 4 ms 2116 KB Output is correct
37 Correct 4 ms 2636 KB Output is correct
38 Correct 5 ms 2732 KB Output is correct
39 Correct 4 ms 2720 KB Output is correct
40 Correct 3 ms 2764 KB Output is correct
41 Correct 4 ms 2764 KB Output is correct
42 Correct 4 ms 2636 KB Output is correct
43 Correct 2 ms 1704 KB Output is correct
44 Correct 3 ms 1872 KB Output is correct
45 Correct 3 ms 2704 KB Output is correct
46 Correct 3 ms 2704 KB Output is correct
47 Correct 3 ms 2764 KB Output is correct
48 Correct 3 ms 2736 KB Output is correct
49 Correct 3 ms 1740 KB Output is correct
50 Correct 5 ms 2736 KB Output is correct
51 Correct 4 ms 2832 KB Output is correct
52 Correct 4 ms 2240 KB Output is correct
53 Correct 3 ms 2632 KB Output is correct
54 Correct 3 ms 3032 KB Output is correct
55 Correct 2 ms 3032 KB Output is correct
56 Correct 2 ms 3032 KB Output is correct