# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
63294 |
2018-08-01T09:28:36 Z |
imeimi2000 |
Vim (BOI13_vim) |
C++17 |
|
89 ms |
23164 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
int n;
char in[70001];
int str[70001];
int ch[70001];
const int inf = 1e8;
int dp1[70001][10];
int dp2[70001][10][10];
void setMin(int &x, int y) {
if (x > y) x = y;
}
int main() {
scanf("%*d%s", in);
int er = 0;
for (int i = 0, fs = 0; in[i]; ++i) {
if (in[i] == 'e') {
er += 2;
fs = 1;
}
else {
if (fs) ch[n] = 1, fs = 0;
str[n] = in[i] - 'a';
if (in[i] > 'e') --str[n];
++n;
}
}
for (int i = 0; i < 10; ++i) {
dp1[0][i] = inf;
for (int j = 0; j < 10; ++j) {
dp2[0][i][j] = inf;
}
}
dp1[0][str[0]] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 10; ++j) {
dp1[i + 1][j] = inf;
if (j != str[i] && !ch[i]) setMin(dp1[i + 1][j], dp1[i][j]);
if (j != str[i]) setMin(dp1[i + 1][j], dp2[i][str[i]][j]);
setMin(dp1[i + 1][j], dp1[i][str[i]] + 2);
setMin(dp1[i + 1][j], dp2[i][str[i]][str[i]] + 2);
for (int k = 0; k < 10; ++k) {
dp2[i + 1][j][k] = inf;
setMin(dp2[i + 1][j][k], dp1[i][str[i]] + 5);
setMin(dp2[i + 1][j][k], dp2[i][str[i]][str[i]] + 5);
if (j != str[i]) {
setMin(dp2[i + 1][j][k], dp1[i][j] + 3);
setMin(dp2[i + 1][j][k], dp2[i][j][str[i]] + 3);
}
if (k != str[i]) {
setMin(dp2[i + 1][j][k], dp2[i][str[i]][k] + 3);
}
if (j != str[i] && k != str[i])
setMin(dp2[i + 1][j][k], dp2[i][j][k] + 1);
}
}
}
printf("%d\n", dp1[n][9] + er - 2);
return 0;
}
Compilation message
vim.cpp: In function 'int main()':
vim.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%*d%s", in);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
560 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
720 KB |
Output is correct |
8 |
Correct |
2 ms |
720 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
2 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
720 KB |
Output is correct |
12 |
Correct |
2 ms |
720 KB |
Output is correct |
13 |
Correct |
3 ms |
720 KB |
Output is correct |
14 |
Correct |
3 ms |
720 KB |
Output is correct |
15 |
Correct |
3 ms |
720 KB |
Output is correct |
16 |
Correct |
3 ms |
720 KB |
Output is correct |
17 |
Correct |
3 ms |
720 KB |
Output is correct |
18 |
Correct |
4 ms |
720 KB |
Output is correct |
19 |
Correct |
3 ms |
720 KB |
Output is correct |
20 |
Correct |
3 ms |
720 KB |
Output is correct |
21 |
Correct |
3 ms |
828 KB |
Output is correct |
22 |
Correct |
3 ms |
828 KB |
Output is correct |
23 |
Correct |
4 ms |
828 KB |
Output is correct |
24 |
Correct |
3 ms |
828 KB |
Output is correct |
25 |
Correct |
3 ms |
828 KB |
Output is correct |
26 |
Correct |
3 ms |
828 KB |
Output is correct |
27 |
Correct |
2 ms |
828 KB |
Output is correct |
28 |
Correct |
3 ms |
828 KB |
Output is correct |
29 |
Correct |
3 ms |
828 KB |
Output is correct |
30 |
Correct |
3 ms |
828 KB |
Output is correct |
31 |
Correct |
3 ms |
828 KB |
Output is correct |
32 |
Correct |
4 ms |
828 KB |
Output is correct |
33 |
Correct |
2 ms |
828 KB |
Output is correct |
34 |
Correct |
3 ms |
828 KB |
Output is correct |
35 |
Correct |
2 ms |
828 KB |
Output is correct |
36 |
Correct |
2 ms |
828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1404 KB |
Output is correct |
2 |
Correct |
6 ms |
1788 KB |
Output is correct |
3 |
Correct |
3 ms |
1788 KB |
Output is correct |
4 |
Correct |
4 ms |
1788 KB |
Output is correct |
5 |
Correct |
6 ms |
1788 KB |
Output is correct |
6 |
Correct |
7 ms |
2172 KB |
Output is correct |
7 |
Correct |
4 ms |
2172 KB |
Output is correct |
8 |
Correct |
5 ms |
2172 KB |
Output is correct |
9 |
Correct |
6 ms |
2172 KB |
Output is correct |
10 |
Correct |
5 ms |
2172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
20220 KB |
Output is correct |
2 |
Correct |
62 ms |
20220 KB |
Output is correct |
3 |
Correct |
49 ms |
20476 KB |
Output is correct |
4 |
Correct |
47 ms |
20820 KB |
Output is correct |
5 |
Correct |
63 ms |
23036 KB |
Output is correct |
6 |
Correct |
36 ms |
23036 KB |
Output is correct |
7 |
Correct |
46 ms |
23036 KB |
Output is correct |
8 |
Correct |
48 ms |
23036 KB |
Output is correct |
9 |
Correct |
49 ms |
23036 KB |
Output is correct |
10 |
Correct |
37 ms |
23036 KB |
Output is correct |
11 |
Correct |
48 ms |
23036 KB |
Output is correct |
12 |
Correct |
52 ms |
23164 KB |
Output is correct |
13 |
Correct |
89 ms |
23164 KB |
Output is correct |
14 |
Correct |
53 ms |
23164 KB |
Output is correct |
15 |
Correct |
48 ms |
23164 KB |
Output is correct |
16 |
Correct |
44 ms |
23164 KB |
Output is correct |
17 |
Correct |
49 ms |
23164 KB |
Output is correct |
18 |
Correct |
58 ms |
23164 KB |
Output is correct |
19 |
Correct |
45 ms |
23164 KB |
Output is correct |
20 |
Correct |
41 ms |
23164 KB |
Output is correct |