Submission #202323

# Submission time Handle Problem Language Result Execution time Memory
202323 2020-02-15T10:01:37 Z giorgikob JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
33 ms 2424 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

const int N = 1e6 + 69;

int n,x,k,l,r;

int B[N],ANS[N];

int A[N],ans;

vector<int> v[3];

int main(){

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        char c;
        cin>>c;
        if(c == 'J') A[i] = 0;
        if(c == 'O') A[i] = 1;
        if(c == 'I') A[i] = 2;
        v[ A[i] ].pb(i);
    }

    ans = 1e9;

    for(int i=0;i<v[0].size()-k+1;i++){

        l = v[0][i];

        r = v[0][i+k-1];

        bool ok = true;

        for(int j=1;j<=2;j++){
            vector<int> :: iterator it;
            it = upper_bound(v[j].begin(),v[j].end(),r);

            if(it == v[j].end()){
                ok = false;
                break;
            }

            if(it-v[j].begin()+k-1 >= v[j].size()){
                ok = false;
                break;
            }

            r = v[j][it-v[j].begin()+k-1];
        }

        if(!ok){
            break;
        }

        ans = min(ans,r-l-3*k+1);


    }

    if(ans == 1e9){
        ans = -1;
    }

    cout<<ans<<endl;

}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[0].size()-k+1;i++){
                 ~^~~~~~~~~~~~~~~~
ho_t2.cpp:49:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(it-v[j].begin()+k-1 >= v[j].size()){
                ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 456 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 456 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 280 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 6 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 456 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 280 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 6 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 30 ms 1908 KB Output is correct
37 Correct 33 ms 2296 KB Output is correct
38 Correct 33 ms 2292 KB Output is correct
39 Correct 31 ms 2424 KB Output is correct
40 Correct 27 ms 2292 KB Output is correct
41 Correct 30 ms 2288 KB Output is correct
42 Correct 33 ms 2292 KB Output is correct
43 Correct 17 ms 1528 KB Output is correct
44 Correct 21 ms 1648 KB Output is correct
45 Correct 26 ms 2288 KB Output is correct
46 Correct 28 ms 2284 KB Output is correct
47 Correct 24 ms 2292 KB Output is correct
48 Correct 24 ms 2420 KB Output is correct
49 Correct 18 ms 1780 KB Output is correct
50 Correct 25 ms 2292 KB Output is correct
51 Correct 25 ms 2288 KB Output is correct
52 Correct 24 ms 1908 KB Output is correct
53 Correct 25 ms 2288 KB Output is correct
54 Correct 25 ms 2416 KB Output is correct
55 Correct 24 ms 2416 KB Output is correct
56 Correct 23 ms 2416 KB Output is correct