Submission #956337

# Submission time Handle Problem Language Result Execution time Memory
956337 2024-04-01T16:14:27 Z Dennis_Jason JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
6 ms 23896 KB
#include <bits/stdc++.h>
#define NMAX 500001
#define pb push_back
#define MOD 1000000007
#define nl '\n'
#define INF 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
int n,k,ans=INF;
string s;
set<int>v[NMAX];
char J='J';
char O='O';
char I='I';

signed main() {
    cin>>n>>k;

    cin>>s;
    for(int i=0;i<n;++i)
    {
        v[s[i]-'0'].insert(i);
    }

    if(v[J-'0'].size()<k||v[O-'0'].size()<k||v[I-'0'].size()<k)
    {
        fout<<-1;
        return 0;
    }


    for(int i=0;i<v[J-'0'].size()-k+1;++i)
    {
        auto it_J=v[J-'0'].begin();
        advance(it_J,i+k-1);
        if(*it_J>=n-1)
            continue;
        auto it_O= upper_bound(v[O-'0'].begin(),v[O-'0'].end(),*it_J);
        advance(it_O,k-1);
        if(*it_O>=n-1)
            continue;

        auto it_I= upper_bound(v[I-'0'].begin(),v[I-'0'].end(),*it_O);
        advance(it_I,k-1);
        cout<<(*it_J-k)<<" "<<(*it_I)<<nl;
        ans=min(ans,((*it_I-(*it_J-k)+1)-(3*k)));
    }
    if(ans<0)
        cout<<-1;
    else
        cout<<ans;


    return 0;

}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:27:23: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     if(v[J-'0'].size()<k||v[O-'0'].size()<k||v[I-'0'].size()<k)
      |        ~~~~~~~~~~~~~~~^~
ho_t2.cpp:27:42: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     if(v[J-'0'].size()<k||v[O-'0'].size()<k||v[I-'0'].size()<k)
      |                           ~~~~~~~~~~~~~~~^~
ho_t2.cpp:27:61: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     if(v[J-'0'].size()<k||v[O-'0'].size()<k||v[I-'0'].size()<k)
      |                                              ~~~~~~~~~~~~~~~^~
ho_t2.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0;i<v[J-'0'].size()-k+1;++i)
      |                 ~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -