Submission #386090

# Submission time Handle Problem Language Result Execution time Memory
386090 2021-04-05T15:36:01 Z strawberry2005 JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
1 ms 364 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
const int mod = 1e9+7;
#define deb(x) cout<<#x<<": "<<x<<endl

int iceil(int a, int b) {
  return (a + b - 1) / b;
}
signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);

    #ifdef strawberryshaker2005
        freopen("input.txt", "r", stdin);
    #endif

    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<int> J,O,I;
    for(int i=0;i<n;i++){
        if(s[i]=='J') J.push_back(i);
        if(s[i]=='O') O.push_back(i);
        if(s[i]=='I') I.push_back(i);
    }
    int ans=mod;

    for(int i=0;i+k-1<=J.size();i++){
        int start=J[i];
        //deb(J[i]);
        int end=distance(O.begin(),lower_bound(O.begin(),O.end(),J[i+k-1]+1));
        end=end+k-1;
        //deb(end);
        if(end>=O.size()) continue;
        end=O[end];
        end=distance(I.begin(),lower_bound(I.begin(),I.end(),end));
        end=end+k-1;
        if(end>=I.size()) continue;
        end=I[end];
        ans=min(ans,abs(end-start));
    }   
    if(ans==mod) cout<<"-1\n";
    else cout<<ans<<endl;



    return(0);
    
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:34:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0;i+k-1<=J.size();i++){
      |                 ~~~~~^~~~~~~~~~
ho_t2.cpp:40:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if(end>=O.size()) continue;
      |            ~~~^~~~~~~~~~
ho_t2.cpp:44:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         if(end>=I.size()) continue;
      |            ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -