Submission #753873

# Submission time Handle Problem Language Result Execution time Memory
753873 2023-06-06T08:47:02 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
 
#define int long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N = 2e5+10;
const int INF = 1e18;

int po[N];
int so[N];
int si[N];
int pj[N];
int n,k;
string s;

void polve(){
    cin>>n>>k;
    cin>>s;
    if(s[n-1] == 'I') si[n-1] = 1;
    for(int i = n-2;i>=0;i--){
        if(s[i] == 'I') si[i] = si[i+1]+1;
        else si[i] = si[i+1];
    }
    if(s[0] == 'J') pj[0] = 1;
    for(int i = 1;i<n;i++){
        if(s[i] == 'J') pj[i] = pj[i-1]+1;
        else pj[i] = pj[i-1];
    }
    for(int i = 1;i<n;i++){
        if(s[i] == 'O' && pj[i]>=k) po[i] = po[i-1]+1;
        else po[i] = po[i-1];
    }
    for(int i = n-1;i>=0;i--){
        if(s[i] == 'O' && si[i]>=k)  so[i] = so[i+1]+1;
        else so[i] = so[i+1];
    }
    bool ok = 0;
    bool ok1 = 0;
    for(int i=0;i<n;i++){
        if(po[i] >= k ) ok = 1;
        if(so[i] >= k ) ok1 = 1;
    }
    if(!ok || !ok1){
        cout<<-1;
        return;
    }
    for(int i = 0;i<n;i++){
        cout<<pj[i]<<' ';
    }
    cout<<'\n';
    for(int i = 0;i<n;i++){
        cout<<si[i]<<' ';
    }
    cout<<'\n';
    for(int i = 0;i<n;i++){
        cout<<po[i]<<' ';
    }
    cout<<'\n';
    for(int i = 0;i<n;i++){
        cout<<so[i]<<' ';
    }
    cout<<'\n';
    int pos1 = -1;
    int pos2 = -1;
    for(int i= 0;i<n;i++){
        if(s[i] == 'J' && pj[i] >= k && si[i] >= k && so[i] >= k){
            pos1 = i;
        }
    }
    for(int i= n-1;i>=0;i--){
        if(s[i] == 'I' && pj[i] >= k && si[i] >= k && po[i] >= k){
            pos2 = i;
        }
    }
    int cnt1 = k;
    int cnt2 = k;
    for(int i = pos1;cnt1>0;i--){
        if(s[i] == 'J'){
            cnt1--;
            pos1 = i;
        }
    }
    for(int i = pos2;cnt2>0;i++){
        if(s[i] == 'I'){
            cnt2--;
            pos2 = i;
        }
    }
    cout<<pos2-pos1+1-k*3;
}
signed main(){
    // freopen("herding.in","r",stdin);  
    // freopen("herding.out","w",stdout);
    int t = 1;
    // cin>>t;   
    for(int i = 1;i<=t;i++){
        // cout<<"Case "<<i<<":\n";
        polve();
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -