답안 #242460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242460 2020-06-27T18:24:01 Z dolphingarlic Vim (BOI13_vim) C++14
100 / 100
39 ms 22860 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

bool underlined[70000];
int t[70000], p[70000][10], q[70000][10][10];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, t_cnt = 0, e_cnt = 0;
	string s;
	cin >> n >> s;
	underlined[0] = true;
	t[t_cnt++] = s[0] - 'a';
	FOR(i, 1, n) {
		if (s[i] != 'e') {
			if (s[i - 1] == 'e') underlined[t_cnt] = true;
			t[t_cnt++] = s[i] - 'a';
		} else e_cnt++;
	}

	memset(q[0], 0x3f, sizeof q[0]);
	FOR(c, 0, 10) p[0][c] = (c == t[0] ? 0 : 2);
	
	FOR(i, 0, t_cnt) {
		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 (!underlined[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_cnt + p[t_cnt][4] - 2;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 640 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 6 ms 1536 KB Output is correct
3 Correct 5 ms 1024 KB Output is correct
4 Correct 6 ms 1152 KB Output is correct
5 Correct 6 ms 1664 KB Output is correct
6 Correct 7 ms 1920 KB Output is correct
7 Correct 6 ms 1408 KB Output is correct
8 Correct 7 ms 1408 KB Output is correct
9 Correct 6 ms 1536 KB Output is correct
10 Correct 6 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 19960 KB Output is correct
2 Correct 30 ms 19200 KB Output is correct
3 Correct 32 ms 20088 KB Output is correct
4 Correct 34 ms 20472 KB Output is correct
5 Correct 37 ms 22860 KB Output is correct
6 Correct 19 ms 10496 KB Output is correct
7 Correct 28 ms 17152 KB Output is correct
8 Correct 31 ms 19832 KB Output is correct
9 Correct 24 ms 14848 KB Output is correct
10 Correct 24 ms 14080 KB Output is correct
11 Correct 32 ms 20472 KB Output is correct
12 Correct 35 ms 22776 KB Output is correct
13 Correct 35 ms 22520 KB Output is correct
14 Correct 39 ms 22112 KB Output is correct
15 Correct 30 ms 18612 KB Output is correct
16 Correct 31 ms 20088 KB Output is correct
17 Correct 32 ms 19968 KB Output is correct
18 Correct 34 ms 20088 KB Output is correct
19 Correct 31 ms 19072 KB Output is correct
20 Correct 28 ms 16128 KB Output is correct