Submission #996864

# Submission time Handle Problem Language Result Execution time Memory
996864 2024-06-11T11:00:17 Z SuPythony JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n,k; cin>>n>>k;
    string s; cin>>s;
    s="."+s;
    vector<int> J,O,I;
    vector<int> pf(n+1,0);
    for (int i=1; i<=n; i++) {
        if (s[i]=='O') pf[i]=pf[i-1]+1;
        else pf[i]=pf[i-1];
        if (s[i]=='J') J.push_back(i);
        else if (s[i]=='O') O.push_back(i);
        else I.push_back(i);
    }
    if (J.size()<k||O.size()<k||I.size()<k) {
        cout<<-1;
        return 0;
    }
    int lj=-1;
    for (int i=J.size()-1; i>k-2; i--) {
        if (pf[O.back()]-pf[J[i]]>=k) {
            lj=i;
            break;
        }
    }
    if (lj==-1) {
        cout<<-1;
        return 0;
    }
    int ans=J[lj]-J[lj-k+1]-k+1;
    int fi=-1;
    for (int i=0; i<I.size()-k+1; i++) {
        if (pf[I[i]]-pf[J[lj]-1]>=k) {
            fi=i;
            break;
        }
    }
    if (fi==-1) {
        cout<<-1;
        return 0;
    }
    ans+=I[fi+k-1]-I[fi]-k+1;
    ans+=I[fi]-J[lj]-k-1;
    cout<<ans;
    return 0;
}

Compilation message

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