제출 #445446

#제출 시각아이디문제언어결과실행 시간메모리
445446lohachoVim (BOI13_vim)C++14
36.17 / 100
99 ms79912 KiB
#include <bits/stdc++.h>
#define int long long
#define umi(x, y) (x = min(x, y))
#define uma(x, y) (x = max(x, y))
using namespace std;

int dp[70004][12][12];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    string in; cin >> in;
    string s;
    vector<int> must;
    int cnt = 0, ans = 0;
    for(auto&i:in){
        if(i == 'e') ++cnt;
        else{
            s += i; must.push_back(!!cnt);
            ans += cnt * 2;
            cnt = 0;
        }
    }
    while((int)must.size() && !must.back()){
        must.pop_back(); s.pop_back();
    }
    must.push_back(0), s += 'a' + 10;
    n = (int)s.size();
    for(int i = 0; i < 70004; ++i) for(int j = 0; j < 12; ++j) for(int k = 0; k < 12; ++k) dp[i][j][k] = (int)1e9;
    for(int i = 1; i <= 11; ++i) dp[1][i][0] = 0;
    for(int i = 1; i < n; ++i){
        for(int j = 1; j <= 11; ++j){
            for(int k = 0; k <= 11; ++k){
                if(!k){
                    if(!must[i]){
                        umi(dp[i + 1][j][k], dp[i][j][k] + (s[i] - 'a' + 1 == j) * 2);
                    }
                    if(s[i] - 'a' + 1 == j){
                        for(int x = 1; x <= 11; ++x){
                           umi(dp[i + 1][x][k], dp[i][j][k] + (s[i] - 'a' + 1 == j) * 2);
                        }
                    }
                    for(int x = 1; x <= 11; ++x){
                       umi(dp[i + 1][j][x], dp[i][j][k] + 1 + (s[i] - 'a' + 1 == j) * 2);
                    }
                }
                else{
                    if(s[i] - 'a' + 1 == j){
                        umi(dp[i + 1][k][0], dp[i][j][k] + 2 + (s[i] - 'a' + 1 == k) * 2);
                        for(int x = 1; x <= 11; ++x){
                           umi(dp[i + 1][x][k], dp[i][j][k] + 3 + (s[i] - 'a' + 1 == k) * 2);
                        }
                    }
                    else if(s[i] - 'a' + 1 == k){
                        for(int x = 1; x <= 11; ++x){
                           umi(dp[i + 1][j][x], dp[i][j][k] + 3 + (s[i] - 'a' + 1 == j) * 2);
                        }
                    }
                    else{
                        umi(dp[i + 1][j][k], dp[i][j][k] + 1 + (s[i] - 'a' + 1 == k) * 2);
                    }
                }
            }
        }
    }
    cout << ans + dp[n - 1][s[n - 2] - 'a' + 1][11] - 1;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...