Submission #781431

# Submission time Handle Problem Language Result Execution time Memory
781431 2023-07-13T06:19:07 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 328 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
#define OYY 1000000005
#define mod 998244353
#define mid (start+end)/2

vector <pair<int,int>> v;
int dizi[200005],tree[800005];

void build(int node,int start,int end){
    if(start==end){
        tree[node]=dizi[start];
        return ;
    }
    build(node*2,start,mid),build(node*2+1,mid+1,end);
    tree[node]=tree[node*2]+tree[node*2+1];
}

int query(int node,int start,int end,int l,int r){
    if(start>end || start>r || end<l)return 0;
    if(start>=l&& end<=r)return tree[node];
    return query(node*2,start,mid,l,r)+query(node*2+1,mid+1,end,l,r);
}

int32_t main(){
    faster
    int n,k;cin>>n>>k;
    string s,a;cin>>a;
    s="$";
    s+=a;
    int say=0;
    int tut=0;
    char c='J';
    int o=-1;
    for(int i=1;i<=n;i++){
        if(s[i]==c){
            if(o==-1)o=i;
            dizi[i]=1;
            tut++;
        }
        if(tut==k){
            //tut=0;
            c='O';
        }
        else if(tut==2*k){
            c='I';
        }
        else if(tut==3*k){
            v.push_back({o,i});
            o=-1;
            tut=0;
            c='J';
        }
    }
    build(1,1,n);
    int cev=OYY;
    for(int i=0;i<v.size();i++){
        int a=v[i].first;
        int b=v[i].second;
        int deg=query(1,1,n,a,b);
        if(deg>=3*k){
            deg=(b-a)-deg+1;
            cev=min(deg,cev);
        }
    }
    if(cev!=OYY)cout<<cev<<'\n';
    else cout<<-1<<'\n';

    return 0;
}

Compilation message

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:59:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
ho_t2.cpp:33:9: warning: unused variable 'say' [-Wunused-variable]
   33 |     int say=0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -