Submission #452111

# Submission time Handle Problem Language Result Execution time Memory
452111 2021-08-03T19:33:53 Z JovanB JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
9 ms 3800 KB
#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

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 time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 316 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 316 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 0 ms 320 KB Output is correct
36 Correct 6 ms 2908 KB Output is correct
37 Correct 7 ms 3116 KB Output is correct
38 Correct 7 ms 3060 KB Output is correct
39 Correct 9 ms 3160 KB Output is correct
40 Correct 8 ms 3288 KB Output is correct
41 Correct 7 ms 3136 KB Output is correct
42 Correct 7 ms 3164 KB Output is correct
43 Correct 4 ms 2124 KB Output is correct
44 Correct 5 ms 2604 KB Output is correct
45 Correct 7 ms 3288 KB Output is correct
46 Correct 7 ms 3336 KB Output is correct
47 Correct 7 ms 3288 KB Output is correct
48 Correct 8 ms 3288 KB Output is correct
49 Correct 5 ms 2264 KB Output is correct
50 Correct 8 ms 3288 KB Output is correct
51 Correct 7 ms 3320 KB Output is correct
52 Correct 7 ms 3672 KB Output is correct
53 Correct 6 ms 3664 KB Output is correct
54 Correct 5 ms 3140 KB Output is correct
55 Correct 5 ms 3544 KB Output is correct
56 Correct 5 ms 3800 KB Output is correct