Submission #320623

# Submission time Handle Problem Language Result Execution time Memory
320623 2020-11-09T09:33:32 Z teehandsome JJOOII 2 (JOI20_ho_t2) C++11
100 / 100
11 ms 2160 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T>
void _print(vector<T> x) {for(auto e:x) cerr<<e<<",";}
template<typename T>
void _print(T x) {cerr<<x;}

void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
    _print(H);
    if(sizeof...(T)) cerr<<",";
    else cerr<<"\"]";
    dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)

int n,k;
string s;

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>k>>s;
    vector<int> J,O,I;
    for(int i=0;i<n;i++) {
        if(s[i]=='J') J.push_back(i);
        else if(s[i]=='O') O.push_back(i);
        else I.push_back(i);
    }
    int j_len=J.size(),o_len=O.size(),i_len=I.size();
    if(j_len<k or o_len<k or i_len<k) {
        cout<<"-1"<<endl; return 0;
    }
    int ans=INF;
    //debug(J); debug(O); debug(I);
    for(int i=0;i<o_len-k+1;i++) {
        int first_O=O[i];
        int last_O=O[i+k-1];
        int pos1_I=lower_bound(all(I),last_O)-begin(I);
        if(I[pos1_I]<last_O or pos1_I+k>i_len) continue;
        int last_all=I[pos1_I+k-1];
        int pos2_J=lower_bound(all(J),first_O)-begin(J)-1;
        if(pos2_J<k-1 or J[pos2_J]>first_O) continue;
        int first_all=J[pos2_J-k+1];
        ans=min(ans,last_all-first_all-3*k+1);
    }

    if(ans==INF) cout<<"-1"<<endl;
    else cout<<ans<<endl;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 10 ms 1640 KB Output is correct
37 Correct 11 ms 2096 KB Output is correct
38 Correct 11 ms 1988 KB Output is correct
39 Correct 10 ms 2012 KB Output is correct
40 Correct 9 ms 2032 KB Output is correct
41 Correct 10 ms 1972 KB Output is correct
42 Correct 11 ms 1972 KB Output is correct
43 Correct 5 ms 1420 KB Output is correct
44 Correct 6 ms 1520 KB Output is correct
45 Correct 8 ms 2032 KB Output is correct
46 Correct 8 ms 2024 KB Output is correct
47 Correct 8 ms 2160 KB Output is correct
48 Correct 8 ms 2032 KB Output is correct
49 Correct 6 ms 1396 KB Output is correct
50 Correct 8 ms 2020 KB Output is correct
51 Correct 8 ms 2032 KB Output is correct
52 Correct 4 ms 1648 KB Output is correct
53 Correct 5 ms 1764 KB Output is correct
54 Correct 6 ms 2036 KB Output is correct
55 Correct 4 ms 2036 KB Output is correct
56 Correct 3 ms 2036 KB Output is correct