답안 #448239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448239 2021-07-29T11:35:59 Z prvocislo Vim (BOI13_vim) C++17
100 / 100
116 ms 55048 KB
#include <iostream>
#include <vector>
#include <string>
using namespace std;

const int abc = 11, inf = 1e9 + 5;
void upd(int& a, const int& b) { a = min(a, b); }
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    string s;
    cin >> s;
    int cnte = 0;
    vector<int> t; vector<bool> u;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'e') cnte++;
        else
        {
            t.push_back(s[i] - 'a');
            u.push_back(i && s[i - 1] == 'e');
        }
        //if (s[i] == 'e') cout << 2;
        //else cout << (int)u.back();
    } //cout << endl;
    t.push_back(abc - 1), u.push_back(false);
    int m = t.size();
    vector<vector<int> > p(m, vector<int>(abc, inf));
    vector<vector<vector<int> > > q(m, vector<vector<int> >(abc, vector<int>(abc, inf)));
    p[0][t[0]] = q[0][t[0]][t[0]] = 0;
    for (int a = 0; a < m - 1; a++)
    {
        for (int c = 0; c < abc; c++)
        {
            if (!u[a] && c != t[a]) upd(p[a + 1][c], p[a][c]);
            upd(p[a + 1][c], p[a][t[a]] + 2);
            if (c != t[a]) upd(p[a + 1][c], q[a][t[a]][c]);
            upd(p[a + 1][c], q[a][t[a]][t[a]] + 2);
            for (int d = 0; d < abc; d++)
            {
                if (c != t[a]) upd(q[a + 1][c][d], p[a][c] + 3);
                upd(q[a + 1][c][d], p[a][t[a]] + 5);
                if (c != t[a] && d != t[a]) upd(q[a + 1][c][d], q[a][c][d] + 1);
                if (c != t[a]) upd(q[a + 1][c][d], q[a][c][t[a]] + 3);
                if (d != t[a]) upd(q[a + 1][c][d], q[a][t[a]][d] + 3);
                upd(q[a + 1][c][d], q[a][t[a]][t[a]] + 5);
            }
        }
    }
    cout << p[m - 1][abc - 1] - 2 + cnte * 2 << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 564 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 564 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 432 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 2 ms 716 KB Output is correct
24 Correct 1 ms 588 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2252 KB Output is correct
2 Correct 6 ms 3132 KB Output is correct
3 Correct 3 ms 1740 KB Output is correct
4 Correct 5 ms 2252 KB Output is correct
5 Correct 6 ms 3276 KB Output is correct
6 Correct 8 ms 4172 KB Output is correct
7 Correct 5 ms 2764 KB Output is correct
8 Correct 6 ms 2712 KB Output is correct
9 Correct 6 ms 3160 KB Output is correct
10 Correct 7 ms 3276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 48096 KB Output is correct
2 Correct 96 ms 46144 KB Output is correct
3 Correct 100 ms 48720 KB Output is correct
4 Correct 105 ms 49376 KB Output is correct
5 Correct 116 ms 55044 KB Output is correct
6 Correct 53 ms 25076 KB Output is correct
7 Correct 84 ms 41152 KB Output is correct
8 Correct 98 ms 47936 KB Output is correct
9 Correct 73 ms 35564 KB Output is correct
10 Correct 70 ms 33796 KB Output is correct
11 Correct 101 ms 49396 KB Output is correct
12 Correct 115 ms 55048 KB Output is correct
13 Correct 112 ms 54268 KB Output is correct
14 Correct 111 ms 53380 KB Output is correct
15 Correct 92 ms 44820 KB Output is correct
16 Correct 100 ms 48656 KB Output is correct
17 Correct 101 ms 48056 KB Output is correct
18 Correct 103 ms 48736 KB Output is correct
19 Correct 95 ms 46044 KB Output is correct
20 Correct 82 ms 38728 KB Output is correct