답안 #584054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584054 2022-06-26T17:25:11 Z sofijavelkovska JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
25 ms 3172 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k, m=-1, x, y, z, t, i;
    string s;
    cin >> n >> k >> s;
    int aj[n], ao[n], ai[n];
    if (s[0]=='J')
    {
        aj[0]=1;
        ao[0]=1;
        ai[0]=1;
    }
    if (s[0]=='O')
    {
        aj[0]=0;
        ao[0]=1;
        ai[0]=0;
    }
    if (s[0]=='I')
    {
        aj[0]=0;
        ao[0]=0;
        ai[0]=1;
    }
    for (i=1; i<n; i++)
    {
        if (s[i]=='J')
            aj[i]=aj[i-1]+1;
        else
            aj[i]=aj[i-1];
    }
    for (i=1; i<n; i++)
    {
        if (s[i]=='O')
            ao[i]=ao[i-1]+1;
        else
            ao[i]=ao[i-1];
    }
    for (i=1; i<n; i++)
    {
        if (s[i]=='I')
            ai[i]=ai[i-1]+1;
        else
            ai[i]=ai[i-1];
    }
    for (i=0; i<n; i++)
        if (s[i]=='J')
        {
            //cout << i << " ";
            if (i!=0)
                t=k+aj[i-1];
            else
                t=k;
            x=lower_bound(aj, aj+n, t)-aj;
            //cout << x << " ";
            if (x==n)
                continue;
            t=k+ao[x];
            y=lower_bound(ao, ao+n, t)-ao;
            //cout << y << " ";
            if (y==n)
                continue;
            t=k+ai[y];
            z=lower_bound(ai, ai+n, t)-ai;
            //cout << z << endl;
            if (z==n)
                continue;
            if (m==-1 || z-i+1-3*k<m)
                m=z-i+1-3*k;
        }
    cout << m;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 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 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 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 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 300 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 300 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 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 304 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 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 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 300 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 300 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 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 304 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 19 ms 2872 KB Output is correct
37 Correct 20 ms 3140 KB Output is correct
38 Correct 21 ms 3044 KB Output is correct
39 Correct 20 ms 3140 KB Output is correct
40 Correct 17 ms 3136 KB Output is correct
41 Correct 21 ms 3172 KB Output is correct
42 Correct 25 ms 3044 KB Output is correct
43 Correct 10 ms 2120 KB Output is correct
44 Correct 14 ms 2532 KB Output is correct
45 Correct 15 ms 3044 KB Output is correct
46 Correct 16 ms 3172 KB Output is correct
47 Correct 15 ms 3044 KB Output is correct
48 Correct 17 ms 3100 KB Output is correct
49 Correct 10 ms 2244 KB Output is correct
50 Correct 15 ms 3044 KB Output is correct
51 Correct 14 ms 3044 KB Output is correct
52 Correct 14 ms 3040 KB Output is correct
53 Correct 13 ms 3044 KB Output is correct
54 Correct 15 ms 3044 KB Output is correct
55 Correct 11 ms 3140 KB Output is correct
56 Correct 10 ms 3140 KB Output is correct