Submission #320621

# Submission time Handle Problem Language Result Execution time Memory
320621 2020-11-09T09:24:40 Z teehandsome JJOOII 2 (JOI20_ho_t2) C++11
0 / 100
1 ms 364 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;
    for(int i=0;i<o_len-k+1;i++) {
        int total=O[i+k-1]-O[i]-k+1;
        int r=lower_bound(all(J),O[i])-begin(J)-1;
        //debug(i,r);
        if(r<k-1 or r<0) continue;
        total+=J[r]-J[r-k+1]-k+1;
        int l=lower_bound(all(I),O[i+k-1])-begin(I);
        //debug(i,l);
        if(l+k>i_len or I[i_len-1]<O[i+k-1]) continue;
        total+=I[l+k-1]-I[l]-k+1;
        ans=min(ans,total);
    }

    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 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -