답안 #927743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927743 2024-02-15T09:46:29 Z weakweakweak JJOOII 2 (JOI20_ho_t2) C++14
13 / 100
7 ms 3816 KB
/*
5:05開始,也不算是virtual,因為我已經知道幾個人的分數了,也在去年資芽時聽過p4的題敘並想過。
所以就只是計時練習,應該會寫到19:05,然後等家長買晚餐回來吃後再把剩下的兩小時用一用,衝到div2就打div2
目標日本選訓!!
*/
//喔,就只是雙指針而已
#include <bits/stdc++.h>
using namespace std;

string s;
int n, k, a[310000] = {0};
int wow[210000][3];

int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    cin >> s;
    for (int i = 1; i <= n; i++) {
        if (s[i-1] == 'J') a[i] = 0;
        if (s[i-1] == 'O') a[i] = 1;
        if (s[i-1] == 'I') a[i] = 2;
    }

    for (int z = 0; z < 3; z++) {
        for (int i = 1, j = 0, cnt = 0; i <= n; i++) {
            while (j + 1 <= n and cnt < k) {
                j++;
                if (a[j] == z) cnt++;
            }
            if (cnt == k) wow[i][z] = j + 1;
            else wow[i][z] = 209999;
            if (a[i] == z) cnt--;
        }
    }
    for (int i = n + 1; i <= 209999; i++)wow[i][0] = wow[i][1] = 209999, wow[i][2] = n * 114 + 514000;

    int ans = INT_MAX;
    for (int i = 1; i <= n; i++) {
        // cout << i << ' ' << wow[i][0] << ' ' << wow[i][1] << ' ' << wow[i][2] << '\n';
        // cout << i << ' ' << wow[wow[wow[i][0]][1]][2] << '\n';
        ans = min(ans,  wow[wow[wow[i][0]][1]][2]  - i - k * 3 );
    }

    if (ans > n) ans = -1;
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2904 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2904 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2904 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2904 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2904 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2904 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2904 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 1 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2904 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 1 ms 2908 KB Output is correct
22 Correct 1 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 1 ms 2904 KB Output is correct
25 Correct 1 ms 2908 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 1 ms 2904 KB Output is correct
29 Correct 1 ms 2908 KB Output is correct
30 Correct 1 ms 2908 KB Output is correct
31 Correct 1 ms 2908 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 1 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 1 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2904 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2904 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2904 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2904 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 1 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2904 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 1 ms 2908 KB Output is correct
22 Correct 1 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 1 ms 2904 KB Output is correct
25 Correct 1 ms 2908 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 1 ms 2904 KB Output is correct
29 Correct 1 ms 2908 KB Output is correct
30 Correct 1 ms 2908 KB Output is correct
31 Correct 1 ms 2908 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 1 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 1 ms 2908 KB Output is correct
36 Correct 6 ms 3812 KB Output is correct
37 Correct 6 ms 3812 KB Output is correct
38 Correct 6 ms 3816 KB Output is correct
39 Incorrect 7 ms 3816 KB Output isn't correct
40 Halted 0 ms 0 KB -