Submission #119130

# Submission time Handle Problem Language Result Execution time Memory
119130 2019-06-20T12:26:54 Z tmwilliamlin168 Vim (BOI13_vim) C++14
100 / 100
67 ms 22916 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN=7e4;
int n, a1, t[mxN+1], m, dp1[mxN+1][10], dp2[mxN+1][10][10];
string s;
bool u[mxN];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> s;
	for(int i=0, j=0; i<n; ++i) {
		if(s[i]=='e') {
			a1+=2;
			j=1;
		} else {
			t[m]=s[i]-'a'-(s[i]>'e');
			u[m++]=j;
			j=0;
		}
	}
	t[m]=9;
	memset(dp2[0], 0x3f, sizeof(dp2[0]));
	for(int i=0; i<10; ++i)
		dp1[0][i]=t[0]==i?0:2;
	auto a=[](bool b) {
		return b?9*n:0;
	};
	for(int i=0; i<m; ++i) {
		for(int j=0; j<10; ++j) {
			dp1[i+1][j]=min({dp1[i][j]+a(j==t[i])+a(u[i]), dp1[i][t[i]]+2, dp2[i][t[i]][j]+a(j==t[i]), dp2[i][t[i]][t[i]]+2});
			for(int k=0; k<10; ++k)
				dp2[i+1][j][k]=min({dp1[i][j]+3+a(j==t[i]), dp1[i][t[i]]+5, dp2[i][j][k]+1+a(j==t[i])+a(k==t[i]), dp2[i][j][t[i]]+3+a(j==t[i]), dp2[i][t[i]][k]+3+a(k==t[i]), dp2[i][t[i]][t[i]]+5});
		}
	}
	cout << a1+dp1[m][9]-2;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 400 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 13 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1152 KB Output is correct
2 Correct 5 ms 1536 KB Output is correct
3 Correct 4 ms 896 KB Output is correct
4 Correct 4 ms 1152 KB Output is correct
5 Correct 5 ms 1664 KB Output is correct
6 Correct 6 ms 1920 KB Output is correct
7 Correct 5 ms 1408 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 5 ms 1536 KB Output is correct
10 Correct 6 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 19876 KB Output is correct
2 Correct 56 ms 19164 KB Output is correct
3 Correct 58 ms 20216 KB Output is correct
4 Correct 67 ms 20600 KB Output is correct
5 Correct 67 ms 22908 KB Output is correct
6 Correct 35 ms 10616 KB Output is correct
7 Correct 53 ms 17144 KB Output is correct
8 Correct 61 ms 20060 KB Output is correct
9 Correct 46 ms 14840 KB Output is correct
10 Correct 44 ms 14072 KB Output is correct
11 Correct 62 ms 20620 KB Output is correct
12 Correct 67 ms 22916 KB Output is correct
13 Correct 67 ms 22520 KB Output is correct
14 Correct 66 ms 22108 KB Output is correct
15 Correct 59 ms 18680 KB Output is correct
16 Correct 58 ms 20216 KB Output is correct
17 Correct 59 ms 19948 KB Output is correct
18 Correct 62 ms 20216 KB Output is correct
19 Correct 58 ms 19192 KB Output is correct
20 Correct 49 ms 16248 KB Output is correct