Submission #242461

#TimeUsernameProblemLanguageResultExecution timeMemory
242461dolphingarlicVim (BOI13_vim)C++14
100 / 100
39 ms22776 KiB
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) using namespace std;bool u[70000];int t[70000], p[70000][10], q[70000][10][10];int main() {ios_base::sync_with_stdio(0);cin.tie(0);int n, m = 0, e = 0;string s;cin >> n >> s;u[0] = true;t[m++] = s[0] - 'a';FOR(i, 1, n) {if (s[i] != 'e') {if (s[i - 1] == 'e') u[m] = true;t[m++] = s[i] - 'a';} else e++;}memset(q[0], 0x3f, sizeof q[0]);FOR(c, 0, 10) p[0][c] = (c == t[0] ? 0 : 2);FOR(i, 0, m) {FOR(c, 0, 10) {p[i + 1][c] = min(p[i][t[i]], q[i][t[i]][t[i]]) + 2;if (c != t[i]) {p[i + 1][c] = min(p[i + 1][c], q[i][t[i]][c]);if (!u[i]) p[i + 1][c] = min(p[i + 1][c], p[i][c]);}FOR(d, 0, 10) {q[i + 1][c][d] = min(p[i][t[i]], q[i][t[i]][t[i]]) + 5;if (c != t[i]) {q[i + 1][c][d] = min(q[i + 1][c][d], min(p[i][c], q[i][c][t[i]]) + 3);if (d != t[i]) q[i + 1][c][d] = min(q[i + 1][c][d], q[i][c][d] + 1);}if (d != t[i]) q[i + 1][c][d] = min(q[i + 1][c][d], q[i][t[i]][d] + 3);}}}cout << 2 * e + p[m][4] - 2;return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...