Submission #203212

# Submission time Handle Problem Language Result Execution time Memory
203212 2020-02-19T20:05:53 Z jovan_b JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
13 ms 3716 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(s[i] == 'O'){
            q2.push_front(i);
        }
        if(s[i] == 'I'){
            q3.push_front(i);
        }
        if(q1.size() > k) q1.pop_back();
        if(q1.size() == k) dp1[i] = q1.back();
        if(q2.size() > k) q2.pop_back();
        if(q2.size() == k) dp2[i] = q2.back();
        if(q3.size() > k) q3.pop_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:34:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q1.size() > k) q1.pop_back();
            ~~~~~~~~~~^~~
ho_t2.cpp:35:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q1.size() == k) dp1[i] = q1.back();
            ~~~~~~~~~~^~~~
ho_t2.cpp:36:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q2.size() > k) q2.pop_back();
            ~~~~~~~~~~^~~
ho_t2.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q2.size() == k) dp2[i] = q2.back();
            ~~~~~~~~~~^~~~
ho_t2.cpp:38:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q3.size() > k) q3.pop_back();
            ~~~~~~~~~~^~~
ho_t2.cpp:39:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q3.size() == k) dp3[i] = q3.back();
            ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 4 ms 380 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 4 ms 380 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 372 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 380 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 380 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 4 ms 380 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 372 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 380 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 380 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 11 ms 2820 KB Output is correct
37 Correct 12 ms 2948 KB Output is correct
38 Correct 12 ms 2948 KB Output is correct
39 Correct 12 ms 2948 KB Output is correct
40 Correct 12 ms 3076 KB Output is correct
41 Correct 11 ms 2948 KB Output is correct
42 Correct 12 ms 2948 KB Output is correct
43 Correct 9 ms 2040 KB Output is correct
44 Correct 10 ms 2564 KB Output is correct
45 Correct 11 ms 3204 KB Output is correct
46 Correct 11 ms 3204 KB Output is correct
47 Correct 13 ms 3204 KB Output is correct
48 Correct 11 ms 3204 KB Output is correct
49 Correct 9 ms 2180 KB Output is correct
50 Correct 11 ms 3204 KB Output is correct
51 Correct 11 ms 3200 KB Output is correct
52 Correct 10 ms 3460 KB Output is correct
53 Correct 11 ms 3592 KB Output is correct
54 Correct 10 ms 2948 KB Output is correct
55 Correct 9 ms 3460 KB Output is correct
56 Correct 9 ms 3716 KB Output is correct