답안 #503978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503978 2022-01-09T10:55:13 Z qwerasdfzxcl Vim (BOI13_vim) C++14
100 / 100
44 ms 29764 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
int dp[70070][12][12], a[70070], on[70070];

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n, pt = 1, cnt = 0;
    string s;
    cin >> n >> s;

    for (int i=0;i<n;i++){
        if (s[i]!='e') {a[pt++] = s[i] - 'a' + 1; continue;}
        while(i<n && s[i]=='e') i++, cnt++;
        on[pt] = 1;
        a[pt++] = s[i] - 'a' + 1;
    }

    n = pt - 1;

    //for (int i=1;i<=n;i++) printf("%c", a[i]+'a'-1);
    //printf("\n");
    //for (int i=1;i<=n;i++) printf("%d", on[i]);
    //printf("\n");

    for (int j=1;j<=10;j++){
        for (int k=1;k<=10;k++) dp[1][j][k] = 4;
        dp[1][j][0] = 2;
        dp[1][j][11] = 2;
    }

    for (int i=2;i<=n;i++){
        for (int j=1;j<=10;j++){
            for (int k=1;k<=10;k++){
                dp[i][j][k] = 1e9;
                if (a[i]!=j && a[i]!=k) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k] + 1);
                if (a[i]!=j) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][a[i]] + 3);
                if (a[i]!=k) dp[i][j][k] = min(dp[i][j][k], dp[i-1][a[i]][k] + 3);
                dp[i][j][k] = min(dp[i][j][k], dp[i-1][a[i]][a[i]] + 5);

                if (a[i]!=j) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][0] + 2);
                dp[i][j][k] = min(dp[i][j][k], dp[i-1][a[i]][0] + 4);
            }
        }

        for (int j=1;j<=10;j++){
            dp[i][j][0] = 1e9;
            if (a[i]!=j && !on[i]) dp[i][j][0] = min(dp[i][j][0], dp[i-1][j][0]);
            dp[i][j][0] = min(dp[i][j][0], dp[i-1][a[i]][0] + 2);

            if (a[i]!=j) dp[i][j][0] = min(dp[i][j][0], dp[i-1][a[i]][j] + 1);
            dp[i][j][0] = min(dp[i][j][0], dp[i-1][a[i]][a[i]] + 3);


            dp[i][j][11] = 1e9;
            if (a[i]!=j) dp[i][j][11] = min(dp[i][j][11], dp[i-1][j][11] + 1);
            dp[i][j][11] = min(dp[i][j][11], dp[i-1][a[i]][11] + 3);

            if (a[i]!=j) dp[i][j][11] = min(dp[i][j][11], dp[i-1][j][0]);
            dp[i][j][11] = min(dp[i][j][11], dp[i-1][a[i]][0] + 2);
        }

        dp[i][11][0] = 1e9;
        if (!on[i]) dp[i][11][0] = min(dp[i][11][0], dp[i-1][11][0]);
        dp[i][11][0] = min(dp[i][11][0], dp[i-1][a[i]][0]);

        dp[i][11][0] = min(dp[i][11][0], dp[i-1][a[i]][11] + 1);
        dp[i][11][0] = min(dp[i][11][0], dp[i-1][a[i]][a[i]] + 2);
    }

    //printf("%d\n", dp[1][4][0]);
    printf("%d\n", dp[n][11][0] + cnt*2);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 452 KB Output is correct
32 Correct 1 ms 452 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1356 KB Output is correct
2 Correct 2 ms 1740 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 2 ms 1356 KB Output is correct
5 Correct 3 ms 1868 KB Output is correct
6 Correct 3 ms 2380 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 3 ms 1612 KB Output is correct
9 Correct 2 ms 1740 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 25876 KB Output is correct
2 Correct 33 ms 24788 KB Output is correct
3 Correct 38 ms 26216 KB Output is correct
4 Correct 36 ms 26720 KB Output is correct
5 Correct 39 ms 29764 KB Output is correct
6 Correct 19 ms 13624 KB Output is correct
7 Correct 30 ms 22272 KB Output is correct
8 Correct 34 ms 26048 KB Output is correct
9 Correct 25 ms 19312 KB Output is correct
10 Correct 25 ms 18328 KB Output is correct
11 Correct 36 ms 26692 KB Output is correct
12 Correct 44 ms 29700 KB Output is correct
13 Correct 40 ms 29356 KB Output is correct
14 Correct 38 ms 28728 KB Output is correct
15 Correct 32 ms 24264 KB Output is correct
16 Correct 36 ms 26284 KB Output is correct
17 Correct 34 ms 25868 KB Output is correct
18 Correct 35 ms 26288 KB Output is correct
19 Correct 34 ms 24776 KB Output is correct
20 Correct 28 ms 20952 KB Output is correct