Submission #211467

# Submission time Handle Problem Language Result Execution time Memory
211467 2020-03-20T12:35:12 Z brcode JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
19 ms 5580 KB
#include <iostream>

using namespace std;
const int MAXN = 5e5+5;
int indj[MAXN];
int indo[MAXN];
int indi[MAXN];
int prefj[MAXN];
int prefo[MAXN];
int prefi[MAXN];
int ans = 1e9;
int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    s = '#'+s;
    for(int i=0;i<=n;i++){
        indj[i] = 1e9;
        indo[i] = 1e9;
        indi[i] = 1e9;
    }
    for(int i=1;i<=n;i++){
        prefj[i] = prefj[i-1]+(s[i]=='J');
        prefo[i] = prefo[i-1]+(s[i]=='O');
        prefi[i] = prefi[i-1]+(s[i]=='I');
        //cout<<prefj[i]<<" "<<prefo[i]<<" "<<prefi[i]<<endl;
        indj[prefj[i]] = min(indj[prefj[i]],i);
        indo[prefo[i]] = min(indo[prefo[i]],i);
        indi[prefi[i]] = min(indi[prefi[i]],i);
    }
    for(int i=1;i<=n;i++){
        int nxt = indj[prefj[i-1]+k];
        //cout<<nxt<<endl;
        if(nxt>n){
            break;
        }
        int nxt2 = indo[prefo[nxt]+k];
        
        if(nxt2>n){
            break;
        }
        int r = indi[prefi[nxt2]+k];
        if(r>n){
            break;
        }
        
        ans = min(ans,n-(3*k)-(i-1)-(n-r));
    }
    if(ans == 1e9){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 18 ms 5208 KB Output is correct
37 Correct 18 ms 5580 KB Output is correct
38 Correct 19 ms 5580 KB Output is correct
39 Correct 18 ms 5580 KB Output is correct
40 Correct 18 ms 5580 KB Output is correct
41 Correct 18 ms 5580 KB Output is correct
42 Correct 18 ms 5580 KB Output is correct
43 Correct 14 ms 3604 KB Output is correct
44 Correct 15 ms 4472 KB Output is correct
45 Correct 18 ms 5580 KB Output is correct
46 Correct 17 ms 5580 KB Output is correct
47 Correct 17 ms 5580 KB Output is correct
48 Correct 17 ms 5580 KB Output is correct
49 Correct 13 ms 3724 KB Output is correct
50 Correct 18 ms 5580 KB Output is correct
51 Correct 17 ms 5580 KB Output is correct
52 Correct 17 ms 5460 KB Output is correct
53 Correct 17 ms 5580 KB Output is correct
54 Correct 18 ms 5580 KB Output is correct
55 Correct 17 ms 5580 KB Output is correct
56 Correct 17 ms 5580 KB Output is correct