Submission #1053685

# Submission time Handle Problem Language Result Execution time Memory
1053685 2024-08-11T15:33:40 Z dpsaveslives JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
11 ms 5452 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
int pref[3][MAXN],dp[3][MAXN];
int main(){
    int N,K; cin >> N >> K;
    for(int i = 1;i<=N;++i){
        char c; cin >> c;
        if(c == 'J') pref[0][i]++;
        else if(c == 'O') pref[1][i]++;
        else pref[2][i]++;
        pref[0][i] += pref[0][i-1];
        pref[1][i] += pref[1][i-1];
        pref[2][i] += pref[2][i-1];
    }
    memset(dp[0],0x3f,sizeof(dp[0]));
    int cur = 1e9, pos = 0;
    for(int i = 1;i<=N;++i){
        while(pref[0][i]-pref[0][pos] >= K && pos < i){
            cur = min(cur,-pos);
            pos++;
        }
        dp[0][i] = cur+i;
    }
    memset(dp[1],0x3f,sizeof(dp[1]));
    cur = 1e9; pos = 0;
    for(int i = 1;i<=N;++i){
        while(pref[1][i]-pref[1][pos] >= K && pos < i){
            cur = min(cur,dp[0][pos]-pos);
            pos++;
        }
        dp[1][i] = cur+i;
    }
    memset(dp[2],0x3f,sizeof(dp[2]));
    cur = 1e9; pos = 0;
    for(int i = 1;i<=N;++i){
        while(pref[2][i]-pref[2][pos] >= K && pos < i){
            cur = min(cur,dp[1][pos]-pos);
            pos++;
        }
        dp[2][i] = cur+i;
    }
    int ans = *min_element(dp[2],dp[2]+N+1) - 3*K;
    if(ans > 1e7) cout << -1 << "\n";
    else cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 0 ms 2652 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 0 ms 2652 KB Output is correct
9 Correct 0 ms 2652 KB Output is correct
10 Correct 0 ms 2652 KB Output is correct
11 Correct 0 ms 2652 KB Output is correct
12 Correct 0 ms 2652 KB Output is correct
13 Correct 0 ms 2652 KB Output is correct
14 Correct 0 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 0 ms 2652 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 0 ms 2652 KB Output is correct
9 Correct 0 ms 2652 KB Output is correct
10 Correct 0 ms 2652 KB Output is correct
11 Correct 0 ms 2652 KB Output is correct
12 Correct 0 ms 2652 KB Output is correct
13 Correct 0 ms 2652 KB Output is correct
14 Correct 0 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
17 Correct 0 ms 2652 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 0 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 0 ms 2652 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
25 Correct 0 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 0 ms 2652 KB Output is correct
32 Correct 0 ms 2652 KB Output is correct
33 Correct 0 ms 2652 KB Output is correct
34 Correct 0 ms 2796 KB Output is correct
35 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 0 ms 2652 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 0 ms 2652 KB Output is correct
9 Correct 0 ms 2652 KB Output is correct
10 Correct 0 ms 2652 KB Output is correct
11 Correct 0 ms 2652 KB Output is correct
12 Correct 0 ms 2652 KB Output is correct
13 Correct 0 ms 2652 KB Output is correct
14 Correct 0 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
17 Correct 0 ms 2652 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 0 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 0 ms 2652 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
25 Correct 0 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 0 ms 2652 KB Output is correct
32 Correct 0 ms 2652 KB Output is correct
33 Correct 0 ms 2652 KB Output is correct
34 Correct 0 ms 2796 KB Output is correct
35 Correct 1 ms 2648 KB Output is correct
36 Correct 9 ms 4956 KB Output is correct
37 Correct 10 ms 5212 KB Output is correct
38 Correct 10 ms 5324 KB Output is correct
39 Correct 11 ms 5452 KB Output is correct
40 Correct 10 ms 5212 KB Output is correct
41 Correct 11 ms 5216 KB Output is correct
42 Correct 11 ms 5212 KB Output is correct
43 Correct 6 ms 4188 KB Output is correct
44 Correct 8 ms 4700 KB Output is correct
45 Correct 10 ms 5244 KB Output is correct
46 Correct 10 ms 5208 KB Output is correct
47 Correct 10 ms 5208 KB Output is correct
48 Correct 10 ms 5132 KB Output is correct
49 Correct 7 ms 4444 KB Output is correct
50 Correct 10 ms 5212 KB Output is correct
51 Correct 10 ms 5100 KB Output is correct
52 Correct 8 ms 5036 KB Output is correct
53 Correct 8 ms 5212 KB Output is correct
54 Correct 7 ms 5212 KB Output is correct
55 Correct 7 ms 5212 KB Output is correct
56 Correct 7 ms 5320 KB Output is correct