답안 #927747

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

string s;
int n, k, a[810000] = {0};
int wow[810000][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 (z == 2) wow[i][z] = n * 114 + 514000;
            }
            if (a[i] == z) cnt--;
        }
    }
    wow[0][2] = n * 114 + 514000;
    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 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6788 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6748 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6788 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6748 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 2 ms 6744 KB Output is correct
18 Correct 2 ms 6744 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 2 ms 6796 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6896 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6792 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 6800 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6788 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6748 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 2 ms 6744 KB Output is correct
18 Correct 2 ms 6744 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 2 ms 6796 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6896 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6792 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 6800 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 7 ms 6888 KB Output is correct
37 Correct 7 ms 6884 KB Output is correct
38 Correct 7 ms 7044 KB Output is correct
39 Correct 8 ms 6884 KB Output is correct
40 Correct 9 ms 6884 KB Output is correct
41 Correct 8 ms 6888 KB Output is correct
42 Correct 8 ms 6888 KB Output is correct
43 Correct 5 ms 7032 KB Output is correct
44 Correct 6 ms 6888 KB Output is correct
45 Correct 7 ms 6888 KB Output is correct
46 Correct 8 ms 6888 KB Output is correct
47 Correct 7 ms 6888 KB Output is correct
48 Correct 7 ms 6888 KB Output is correct
49 Correct 5 ms 6888 KB Output is correct
50 Correct 7 ms 6888 KB Output is correct
51 Correct 8 ms 6888 KB Output is correct
52 Correct 4 ms 6888 KB Output is correct
53 Correct 5 ms 6884 KB Output is correct
54 Correct 4 ms 6884 KB Output is correct
55 Correct 4 ms 7140 KB Output is correct
56 Correct 5 ms 6884 KB Output is correct