Submission #452111

#TimeUsernameProblemLanguageResultExecution timeMemory
452111JovanBJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
9 ms3800 KiB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
int dp1[200005];
int dp2[200005];
int dp3[200005];
 
int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;
 
	int n, k;
	cin >> n >> k;
    string s;
    cin >> s;
    deque <int> q1, q2, q3;
    for(int i=n-1; i>=0; i--){
        dp3[i] = n;
        dp2[i] = n;
        dp1[i] = n;
        if(s[i] == 'J'){
            q1.push_front(i);
            if(q1.size() > k) q1.pop_back();
        }
        if(s[i] == 'O'){
            q2.push_front(i);
            if(q2.size() > k) q2.pop_back();
        }
        if(s[i] == 'I'){
            q3.push_front(i);
            if(q3.size() > k) q3.pop_back();
        }
        if(q1.size() == k) dp1[i] = q1.back();
        if(q2.size() == k) dp2[i] = q2.back();
        if(q3.size() == k) dp3[i] = q3.back();
    }
    int res = n+5;
    for(int i=0; i<n; i++){
        int j = dp1[i]+1;
        if(j >= n) continue;
        j = dp2[j]+1;
        if(j >= n) continue;
        j = dp3[j];
        if(j >= n) continue;
        res = min(res, j-i+1);
    }
    if(res == n+5){
        cout << -1;
        return 0;
    }
    cout << res-3*k;
    return 0;
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:27:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             if(q1.size() > k) q1.pop_back();
      |                ~~~~~~~~~~^~~
ho_t2.cpp:31:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |             if(q2.size() > k) q2.pop_back();
      |                ~~~~~~~~~~^~~
ho_t2.cpp:35:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |             if(q3.size() > k) q3.pop_back();
      |                ~~~~~~~~~~^~~
ho_t2.cpp:37:22: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |         if(q1.size() == k) dp1[i] = q1.back();
      |            ~~~~~~~~~~^~~~
ho_t2.cpp:38:22: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         if(q2.size() == k) dp2[i] = q2.back();
      |            ~~~~~~~~~~^~~~
ho_t2.cpp:39:22: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |         if(q3.size() == k) dp3[i] = q3.back();
      |            ~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...