답안 #771970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771970 2023-07-03T12:59:54 Z Trisanu_Das JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
23 ms 3052 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]
    9 |     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]
   10 |     scanf("%s", s+1);
      |     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 1 ms 280 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 1 ms 280 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 16 ms 2772 KB Output is correct
37 Correct 17 ms 2996 KB Output is correct
38 Correct 17 ms 3040 KB Output is correct
39 Correct 19 ms 3028 KB Output is correct
40 Correct 7 ms 3028 KB Output is correct
41 Correct 15 ms 3052 KB Output is correct
42 Correct 23 ms 2992 KB Output is correct
43 Correct 2 ms 2004 KB Output is correct
44 Correct 3 ms 2388 KB Output is correct
45 Correct 4 ms 3024 KB Output is correct
46 Correct 3 ms 3028 KB Output is correct
47 Correct 3 ms 3028 KB Output is correct
48 Correct 3 ms 3004 KB Output is correct
49 Correct 2 ms 2132 KB Output is correct
50 Correct 3 ms 2984 KB Output is correct
51 Correct 3 ms 3044 KB Output is correct
52 Correct 3 ms 2900 KB Output is correct
53 Correct 3 ms 3048 KB Output is correct
54 Correct 8 ms 3008 KB Output is correct
55 Correct 4 ms 3028 KB Output is correct
56 Correct 2 ms 3028 KB Output is correct