Submission #838007

# Submission time Handle Problem Language Result Execution time Memory
838007 2023-08-26T04:20:57 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
6 ms 3288 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
#define all(x)  (x).begin(), (x).end()
#define test    int t; cin >> t; while(t--){solve();}
#define MOD     998244353
int fpb(int a,int b){if(b == 0){return a;}return fpb(b, a%b);}
int kpk(int a,int b){return (a*b)/fpb(a, b);}

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:23: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]
   23 |     for(int i=0; i<S.length(); i++){
      |                  ~^~~~~~~~~~~
ho_t2.cpp:28: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]
   28 |     while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
      |           ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:28: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]
   28 |     while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
      |                                 ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:28: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]
   28 |     while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
      |                                                       ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:31: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]
   31 |         if(indeksJ+k-1 >= J.size()) break;
      |            ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:35: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]
   35 |         if(indeksO+k-1 >= O.size()) break;
      |            ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:39: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]
   39 |         if(indeksI+k-1 >= I.size()) break;
      |            ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:29:20: warning: variable 'awalO' set but not used [-Wunused-but-set-variable]
   29 |         int awalJ, awalO, awalI;
      |                    ^~~~~
ho_t2.cpp:29:27: warning: variable 'awalI' set but not used [-Wunused-but-set-variable]
   29 |         int awalJ, awalO, awalI;
      |                           ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 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 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 252 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 320 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 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 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 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 252 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 320 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 316 KB Output is correct
36 Correct 4 ms 2372 KB Output is correct
37 Correct 5 ms 2892 KB Output is correct
38 Correct 5 ms 2876 KB Output is correct
39 Correct 4 ms 2976 KB Output is correct
40 Correct 4 ms 3020 KB Output is correct
41 Correct 4 ms 3020 KB Output is correct
42 Correct 6 ms 2892 KB Output is correct
43 Correct 3 ms 1820 KB Output is correct
44 Correct 3 ms 2000 KB Output is correct
45 Correct 3 ms 2960 KB Output is correct
46 Correct 3 ms 2960 KB Output is correct
47 Correct 4 ms 3008 KB Output is correct
48 Correct 4 ms 2984 KB Output is correct
49 Correct 2 ms 1868 KB Output is correct
50 Correct 5 ms 3000 KB Output is correct
51 Correct 4 ms 3020 KB Output is correct
52 Correct 3 ms 2368 KB Output is correct
53 Correct 4 ms 2888 KB Output is correct
54 Correct 3 ms 3284 KB Output is correct
55 Correct 3 ms 3288 KB Output is correct
56 Correct 3 ms 3224 KB Output is correct