Submission #568134

# Submission time Handle Problem Language Result Execution time Memory
568134 2022-05-24T16:56:17 Z Ronin13 JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
0 ms 212 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

const int inf = 1e9 + 1;

int main(){
    int n, k; cin >> n >> k;
    string s; cin >> s;
    vector <int> j;
    int ansp[n + 1];
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'O'){
            if(j.size() < k){
                ansp[i] = inf;
            }
            else{
                int x = j[j.size() - 1];
                int y = j[j.size() - k];
                ansp[i] = x - y + 1 - k;
            }
        }
        else if(s[i] == 'J')j.pb(i);
    }

    vector <int> i;
    int anss[n + 1];
    for(int p = s.size() - 1; p >= 0; p--){
            if(s[p] == 'O'){
                if(i.size() < k) anss[p] = inf;
                else{
                     int x = i[i.size() - 1];
                     int y = i[i.size() - k];
                     anss[p] = y - x + 1 - k;
                }
            }
            else{if(s[p] == 'I') i.pb(p);}
    }
    vector <int> os;
    for(int p = 0; p < s.size(); p++) if(s[p] == 'O') os.pb(p);
    int ans = inf;
    for(int i = 0; i <= (int)os.size() - k; i++){
        int x = os[i];
        int y = os[i + k - 1];
        ans = min(ans, ansp[x] + anss[y] + y - x + 1 - k);
    }
    if(ans == inf) cout << -1;
    else cout << ans;
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
ho_t2.cpp:21:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |             if(j.size() < k){
      |                ~~~~~~~~~^~~
ho_t2.cpp:37:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |                 if(i.size() < k) anss[p] = inf;
      |                    ~~~~~~~~~^~~
ho_t2.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int p = 0; p < s.size(); p++) if(s[p] == 'O') os.pb(p);
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -