Submission #227175

# Submission time Handle Problem Language Result Execution time Memory
227175 2020-04-26T10:09:56 Z ho94949 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
29 ms 3200 KB
#include <bits/stdc++.h>
using namespace std;

int N, K;
char s[202020];
int js[202020], os[202020], is[202020];
int main()
{
    scanf("%d%d", &N, &K);
    scanf("%s", s+1);
    for(int i=1; i<=N; ++i)
    {
        js[i] = js[i-1], os[i] = os[i-1], is[i] = is[i-1];
        if(s[i] == 'J') ++js[i];
        if(s[i] == 'O') ++os[i];
        if(s[i] == 'I') ++is[i];
    }
    int ans = -1;
    for(int i=0; i<N; ++i)
    {
        int np = i;
        int jp = lower_bound(js+np, js+N+1, js[np]+K) - js;
        if(jp == N+1) break; 
        int op = lower_bound(os+jp, os+N+1, os[jp]+K) - os;
        if(op == N+1) break; 
        int ip = lower_bound(is+op, is+N+1, is[op]+K) - is;
        if(ip == N+1) break;
        if(ans == -1) ans = ip-np-3*K;
        else ans = min(ans, ip-np-3*K);
    }
    printf("%d\n", ans);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &K);
     ~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", s+1);
     ~~~~~^~~~~~~~~~~
# 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 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 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 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 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 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 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 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 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 416 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 4 ms 384 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 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 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 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 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 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 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 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 416 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 4 ms 384 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 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 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 384 KB Output is correct
36 Correct 23 ms 2816 KB Output is correct
37 Correct 24 ms 3072 KB Output is correct
38 Correct 25 ms 3072 KB Output is correct
39 Correct 28 ms 3200 KB Output is correct
40 Correct 13 ms 3072 KB Output is correct
41 Correct 23 ms 3072 KB Output is correct
42 Correct 29 ms 3072 KB Output is correct
43 Correct 7 ms 2048 KB Output is correct
44 Correct 7 ms 2432 KB Output is correct
45 Correct 8 ms 3072 KB Output is correct
46 Correct 8 ms 3072 KB Output is correct
47 Correct 8 ms 3072 KB Output is correct
48 Correct 8 ms 3072 KB Output is correct
49 Correct 7 ms 2176 KB Output is correct
50 Correct 9 ms 3072 KB Output is correct
51 Correct 8 ms 3072 KB Output is correct
52 Correct 8 ms 2944 KB Output is correct
53 Correct 8 ms 3072 KB Output is correct
54 Correct 13 ms 3072 KB Output is correct
55 Correct 10 ms 3072 KB Output is correct
56 Correct 8 ms 3072 KB Output is correct