답안 #679127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679127 2023-01-07T14:03:02 Z Nahian9696 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
14 ms 3176 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;

#define f0(i,n) for(int32_t i = 0; i <  (n); i++)
#define f1(i,n) for(int32_t i = 1; i <= (n); i++)

#define inp(n) lli n; cin >> n
#define inparr(arr,n) lli arr[n]; f0(t_ind, n) cin >> arr[t_ind]

#define all(x) (x).begin(), (x).end()

int main () {
    inp(n);
    inp(k);

    string s;
    cin >> s;

    int nextkthJ[n];
    int nextkthO[n];
    int nextkthI[n];

    memset(nextkthJ, -1, sizeof(nextkthJ));
    memset(nextkthO, -1, sizeof(nextkthO));
    memset(nextkthI, -1, sizeof(nextkthI));

    int l=0, r=0, cnt = 0;

    while (r < n) {
        if (s[r] == 'J') {
            cnt++;
        }
        if (cnt == k) {
            while(s[l] != 'J') {
                nextkthJ[l] = r;
                l++;
            }
            nextkthJ[l] = r;
            l++;
            cnt--;
        }
        r++;
    }
    
    l=0, r=0, cnt = 0;

    while (r < n) {
        if (s[r] == 'O') {
            cnt++;
        }
        if (cnt == k) {
            while(s[l] != 'O') {
                nextkthO[l] = r;
                l++;
            }
            nextkthO[l] = r;
            l++;
            cnt--;
        }
        r++;
    }

    l=0, r=0, cnt = 0;

    while (r < n) {
        if (s[r] == 'I') {
            cnt++;
        }
        if (cnt == k) {
            while(s[l] != 'I') {
                nextkthI[l] = r;
                l++;
            }
            nextkthI[l] = r;
            l++;
            cnt--;
        }
        r++;
    }


    lli ans = 1e9;
    f0(i, n) {
        if(nextkthJ[i] == -1) break;
        if(nextkthO[nextkthJ[i]] == -1) break;
        if(nextkthI[nextkthO[nextkthJ[i]]] == -1) break;

        ans = min(ans, (lli)nextkthI[nextkthO[nextkthJ[i]]] - i + 1);

    }

    if(ans == 1e9) cout << -1 << endl;
    else cout << ans - 3*k << endl;

    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 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 0 ms 296 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 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 0 ms 296 KB Output is correct
15 Correct 1 ms 300 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 296 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 212 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 304 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 212 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 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 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 0 ms 296 KB Output is correct
15 Correct 1 ms 300 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 296 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 212 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 304 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 212 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 9 ms 2980 KB Output is correct
37 Correct 10 ms 3172 KB Output is correct
38 Correct 10 ms 3172 KB Output is correct
39 Correct 14 ms 3148 KB Output is correct
40 Correct 11 ms 3172 KB Output is correct
41 Correct 13 ms 3172 KB Output is correct
42 Correct 12 ms 3168 KB Output is correct
43 Correct 6 ms 2020 KB Output is correct
44 Correct 7 ms 2532 KB Output is correct
45 Correct 11 ms 3176 KB Output is correct
46 Correct 9 ms 3144 KB Output is correct
47 Correct 10 ms 3176 KB Output is correct
48 Correct 9 ms 3172 KB Output is correct
49 Correct 6 ms 2148 KB Output is correct
50 Correct 9 ms 3172 KB Output is correct
51 Correct 10 ms 3144 KB Output is correct
52 Correct 6 ms 3016 KB Output is correct
53 Correct 7 ms 3044 KB Output is correct
54 Correct 6 ms 3172 KB Output is correct
55 Correct 7 ms 3144 KB Output is correct
56 Correct 6 ms 3140 KB Output is correct