Submission #137488

# Submission time Handle Problem Language Result Execution time Memory
137488 2019-07-28T04:47:13 Z gs14004 Vim (BOI13_vim) C++17
100 / 100
175 ms 34920 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 70005;

int n;
char str[MAXN], buf[MAXN];
int chk[MAXN];
int dp[MAXN][10];
int d2[MAXN][10][10];

int f(int v, int w);
int g(int v, int win, int wout);

int g(int v, int win, int wout){
	if(v == n - 1) return 1e9;
	if(~d2[v][win][wout]) return d2[v][win][wout];
	int ret = 1e9;
	if(win + 'a' == str[v + 1] && wout + 'a' == str[v + 1]){
		for(int i=0; i<10; i++){
			ret = min(ret, f(v + 1, i) + 3);
		}
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				ret = min(ret, g(v + 1, i, j) + 5);
			}
		}
	}
	else if(win + 'a' == str[v + 1]){
		for(int i=0; i<10; i++){
			ret = min(ret, g(v + 1, i, wout) + 3);
		}
		ret = min(ret, f(v + 1, wout) + 1);
	}
	else if(wout + 'a' == str[v + 1]){
		for(int i=0; i<10; i++){
			ret = min(ret, g(v + 1, win, i) + 3);
		}
	}
	else{
		ret = min(ret, g(v + 1, win, wout) + 1);
	}
	return d2[v][win][wout] = ret;
}

int f(int v, int w){
	if(v == n - 1) return w == 4 ? 0 : 1e9;
	if(~dp[v][w]) return dp[v][w];
	int ret = 1e9;
	if(str[v + 1] == w + 'a'){
		for(int i=0; i<10; i++){
			ret = min(ret, f(v + 1, i) + 2);
		}
		return dp[v][w] = ret;
	}
	for(int i=0; i<10; i++){
		ret = min(ret, g(v + 1, w, i) + 2);
	}
	if(!chk[v + 1]) ret = min(ret, f(v + 1, w));
	return dp[v][w] = ret;
}

int main(){
	scanf("%d %s",&n,buf);
	n = 0;
	int ecnt = 0;
	for(int i=0; buf[i]; i++){
		if(buf[i] == 'e'){
			ecnt++;
			chk[n] = 1;
		}
		else str[n++] = buf[i];
	}
	memset(dp, -1, sizeof(dp));
	memset(d2, -1, sizeof(d2));
	int ret = 1e9;
	for(int i=0; i<10; i++){
		ret = min(ret, f(0, i));
	}
	cout << ret + ecnt * 2 << endl;
}

Compilation message

vim.cpp: In function 'int main()':
vim.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %s",&n,buf);
  ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 30460 KB Output is correct
2 Correct 27 ms 30456 KB Output is correct
3 Correct 27 ms 30456 KB Output is correct
4 Correct 27 ms 30456 KB Output is correct
5 Correct 27 ms 30456 KB Output is correct
6 Correct 28 ms 30456 KB Output is correct
7 Correct 28 ms 30456 KB Output is correct
8 Correct 27 ms 30456 KB Output is correct
9 Correct 27 ms 30456 KB Output is correct
10 Correct 27 ms 30456 KB Output is correct
11 Correct 27 ms 30456 KB Output is correct
12 Correct 27 ms 30456 KB Output is correct
13 Correct 27 ms 30428 KB Output is correct
14 Correct 27 ms 30456 KB Output is correct
15 Correct 27 ms 30456 KB Output is correct
16 Correct 28 ms 30456 KB Output is correct
17 Correct 28 ms 30456 KB Output is correct
18 Correct 27 ms 30584 KB Output is correct
19 Correct 33 ms 30456 KB Output is correct
20 Correct 28 ms 30456 KB Output is correct
21 Correct 28 ms 30456 KB Output is correct
22 Correct 27 ms 30456 KB Output is correct
23 Correct 28 ms 30456 KB Output is correct
24 Correct 28 ms 30456 KB Output is correct
25 Correct 28 ms 30456 KB Output is correct
26 Correct 27 ms 30456 KB Output is correct
27 Correct 28 ms 30428 KB Output is correct
28 Correct 28 ms 30584 KB Output is correct
29 Correct 28 ms 30456 KB Output is correct
30 Correct 28 ms 30456 KB Output is correct
31 Correct 28 ms 30456 KB Output is correct
32 Correct 28 ms 30456 KB Output is correct
33 Correct 28 ms 30456 KB Output is correct
34 Correct 27 ms 30456 KB Output is correct
35 Correct 28 ms 30456 KB Output is correct
36 Correct 33 ms 30456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 30556 KB Output is correct
2 Correct 41 ms 30808 KB Output is correct
3 Correct 30 ms 30584 KB Output is correct
4 Correct 31 ms 30584 KB Output is correct
5 Correct 34 ms 30720 KB Output is correct
6 Correct 36 ms 30736 KB Output is correct
7 Correct 33 ms 30712 KB Output is correct
8 Correct 33 ms 30712 KB Output is correct
9 Correct 33 ms 30712 KB Output is correct
10 Correct 33 ms 30712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 34360 KB Output is correct
2 Correct 134 ms 34168 KB Output is correct
3 Correct 152 ms 34388 KB Output is correct
4 Correct 166 ms 34444 KB Output is correct
5 Correct 162 ms 34920 KB Output is correct
6 Correct 86 ms 32540 KB Output is correct
7 Correct 122 ms 33784 KB Output is correct
8 Correct 152 ms 34296 KB Output is correct
9 Correct 111 ms 33528 KB Output is correct
10 Correct 107 ms 33144 KB Output is correct
11 Correct 157 ms 34552 KB Output is correct
12 Correct 175 ms 34808 KB Output is correct
13 Correct 160 ms 34808 KB Output is correct
14 Correct 154 ms 34744 KB Output is correct
15 Correct 136 ms 34040 KB Output is correct
16 Correct 151 ms 34296 KB Output is correct
17 Correct 144 ms 34384 KB Output is correct
18 Correct 145 ms 34424 KB Output is correct
19 Correct 134 ms 34172 KB Output is correct
20 Correct 121 ms 33628 KB Output is correct