답안 #202627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202627 2020-02-17T11:28:27 Z SamAnd JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
43 ms 2940 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;

int n, k;
char a[N];

int p[N][3];

int byn(int x, int j)
{
    int l = x, r = n;
    int ans = n + 1;
    while (l <= r)
    {
        int m = (l + r) / 2;
        if (p[m][j] - p[x - 1][j] >= k)
        {
            ans = m;
            r = m - 1;
        }
        else
            l = m + 1;
    }
    return ans;
}

int main()
{
    scanf("%d%d", &n, &k);
    scanf(" %s", (a + 1));
    for (int i = 1; i <= n; ++i)
    {
        if (a[i] == 'J')
            a[i] = 0;
        else if (a[i] == 'O')
            a[i] = 1;
        else
            a[i] = 2;
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < 3; ++j)
            p[i][j] = p[i - 1][j];
        p[i][a[i]]++;
    }
    int ans = N;
    for (int i = 1; i <= n; ++i)
    {
        int x = byn(i, 0);
        x = byn(x + 1, 1);
        x = byn(x + 1, 2);
        if (x <= n)
            ans = min(ans, x - i + 1 - 3 * k);
    }
    if (ans == N)
        printf("-1\n");
    else
        printf("%d\n", ans);
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:45:18: warning: array subscript has type 'char' [-Wchar-subscripts]
         p[i][a[i]]++;
                  ^
ho_t2.cpp:30: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:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %s", (a + 1));
     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 372 KB Output is correct
3 Correct 5 ms 256 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 256 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 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 372 KB Output is correct
3 Correct 5 ms 256 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 256 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 5 ms 376 KB Output is correct
12 Correct 5 ms 376 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 380 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 380 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 376 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 376 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 408 KB Output is correct
33 Correct 5 ms 380 KB Output is correct
34 Correct 5 ms 380 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 372 KB Output is correct
3 Correct 5 ms 256 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 256 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 5 ms 376 KB Output is correct
12 Correct 5 ms 376 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 380 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 380 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 376 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 376 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 408 KB Output is correct
33 Correct 5 ms 380 KB Output is correct
34 Correct 5 ms 380 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 34 ms 2680 KB Output is correct
37 Correct 38 ms 2904 KB Output is correct
38 Correct 36 ms 2808 KB Output is correct
39 Correct 38 ms 2808 KB Output is correct
40 Correct 31 ms 2896 KB Output is correct
41 Correct 38 ms 2808 KB Output is correct
42 Correct 43 ms 2936 KB Output is correct
43 Correct 19 ms 1912 KB Output is correct
44 Correct 22 ms 2296 KB Output is correct
45 Correct 28 ms 2808 KB Output is correct
46 Correct 28 ms 2808 KB Output is correct
47 Correct 27 ms 2808 KB Output is correct
48 Correct 28 ms 2808 KB Output is correct
49 Correct 20 ms 2040 KB Output is correct
50 Correct 28 ms 2808 KB Output is correct
51 Correct 27 ms 2808 KB Output is correct
52 Correct 18 ms 2808 KB Output is correct
53 Correct 17 ms 2808 KB Output is correct
54 Correct 23 ms 2940 KB Output is correct
55 Correct 18 ms 2808 KB Output is correct
56 Correct 15 ms 2808 KB Output is correct