# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109312 |
2024-11-06T12:10:28 Z |
Kirill22 |
Vim (BOI13_vim) |
C++17 |
|
115 ms |
42588 KB |
#include "bits/stdc++.h"
using namespace std;
const int inf = (int) 1e9, N = (int) 70000 + 22, A = 10;
int n, need[N], add = 0, ans = inf, all = 0;
string s, t = "";
vector<int> pos;
void upd(int& x, int y) {
x = min(x, y);
}
void solve() {
cin >> n >> s;
add = std::count(s.begin(), s.end(), 'e');
if (!add) {
cout << 0 << '\n';
return;
}
for (int i = 0; i < n; i++) {
if (s[i] != 'e') {
if (i && s[i - 1] == 'e') {
need[(int) t.size()] = 1;
pos.push_back((int) t.size());
}
t += s[i];
}
}
t.push_back('e');
s = t, n = (int) s.size(), all = (int) pos.size();
vector dp(n, vector<int> (10, inf));
vector dp2(n, vector (10, vector<int> (10, inf)));
for (int j = 0; j < 10; j++) {
dp[0][j] = 0;
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < 10; j++) {
if (j != s[i - 1] - 'a' && need[i - 1]) {}
else {
upd(dp[i][j], dp[i - 1][j] + 2 * int(s[i] - 'a' == j));
}
upd(dp[i][j], dp[i - 1][s[i - 1] - 'a'] + 2 * int(s[i] - 'a' == j));
upd(dp[i][j], dp2[i - 1][s[i - 1] - 'a'][j] + 2 * int(s[i] - 'a' == j));
upd(dp[i][j], dp2[i - 1][s[i - 1] - 'a'][s[i - 1] - 'a'] + 2 * int(s[i] - 'a' == j));
for (int k = 0; k < 10; k++) {
upd(dp2[i][j][k], dp[i - 1][j] + 2 * int(s[i] - 'a' == j) + 1 + 2 * int(s[i] - 'a' == k));
upd(dp2[i][j][k], dp[i - 1][s[i - 1] - 'a'] + 2 * int(s[i] - 'a' == j) + 1 + 2 * int(s[i] - 'a' == k));
upd(dp2[i][j][k], dp2[i - 1][j][k] + 2 * int(s[i] - 'a' == j) + 1 + 2 * int(s[i] - 'a' == k));
upd(dp2[i][j][k], dp2[i - 1][s[i - 1] - 'a'][k] + 2 * int(s[i] - 'a' == j) + 1 + 2 * int(s[i] - 'a' == k));
upd(dp2[i][j][k], dp2[i - 1][j][s[i - 1] - 'a'] + 2 * int(s[i] - 'a' == j) + 1 + 2 * int(s[i] - 'a' == k));
upd(dp2[i][j][k], dp2[i - 1][s[i - 1] - 'a'][s[i - 1] - 'a'] + 2 * int(s[i] - 'a' == j) + 1 + 2 * int(s[i] - 'a' == k));
}
}
}
cout << dp[n - 1][4] - 2 + 2 * add << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
472 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
2 ms |
476 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
756 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
1 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
27 |
Correct |
2 ms |
608 KB |
Output is correct |
28 |
Correct |
1 ms |
592 KB |
Output is correct |
29 |
Correct |
1 ms |
592 KB |
Output is correct |
30 |
Correct |
2 ms |
592 KB |
Output is correct |
31 |
Correct |
2 ms |
760 KB |
Output is correct |
32 |
Correct |
2 ms |
592 KB |
Output is correct |
33 |
Correct |
2 ms |
592 KB |
Output is correct |
34 |
Correct |
2 ms |
592 KB |
Output is correct |
35 |
Correct |
2 ms |
592 KB |
Output is correct |
36 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1872 KB |
Output is correct |
2 |
Correct |
6 ms |
2524 KB |
Output is correct |
3 |
Correct |
4 ms |
1360 KB |
Output is correct |
4 |
Correct |
4 ms |
2008 KB |
Output is correct |
5 |
Correct |
6 ms |
2652 KB |
Output is correct |
6 |
Correct |
7 ms |
3408 KB |
Output is correct |
7 |
Correct |
5 ms |
2384 KB |
Output is correct |
8 |
Correct |
5 ms |
2556 KB |
Output is correct |
9 |
Correct |
6 ms |
2808 KB |
Output is correct |
10 |
Correct |
6 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
37052 KB |
Output is correct |
2 |
Correct |
76 ms |
35628 KB |
Output is correct |
3 |
Correct |
86 ms |
37608 KB |
Output is correct |
4 |
Correct |
115 ms |
38216 KB |
Output is correct |
5 |
Correct |
103 ms |
42576 KB |
Output is correct |
6 |
Correct |
50 ms |
19392 KB |
Output is correct |
7 |
Correct |
71 ms |
31980 KB |
Output is correct |
8 |
Correct |
88 ms |
36936 KB |
Output is correct |
9 |
Correct |
60 ms |
27464 KB |
Output is correct |
10 |
Correct |
60 ms |
26264 KB |
Output is correct |
11 |
Correct |
89 ms |
38120 KB |
Output is correct |
12 |
Correct |
98 ms |
42588 KB |
Output is correct |
13 |
Correct |
101 ms |
41808 KB |
Output is correct |
14 |
Correct |
103 ms |
41108 KB |
Output is correct |
15 |
Correct |
95 ms |
34636 KB |
Output is correct |
16 |
Correct |
91 ms |
37452 KB |
Output is correct |
17 |
Correct |
106 ms |
36936 KB |
Output is correct |
18 |
Correct |
86 ms |
37424 KB |
Output is correct |
19 |
Correct |
104 ms |
35656 KB |
Output is correct |
20 |
Correct |
69 ms |
30132 KB |
Output is correct |