Submission #256404

# Submission time Handle Problem Language Result Execution time Memory
256404 2020-08-02T16:14:37 Z Saboon Vim (BOI13_vim) C++14
55 / 100
670 ms 193160 KB
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;

const int maxn = 7000 + 10;

int nex[maxn][12];
int dp[maxn][maxn];
int pd[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;
	for (int i = 0; i < 10; i++){
		int last = -1;
		for (int j = n-1; j >= 0; j--){
			if (last == -1)
				nex[j][i] = j;
			else
				nex[j][i] = last;
			if ((int)(s[j] - 'a') == i and s[j] != 'e')
				last = j;
		}
	}
	vector<int> e;
	for (int i = 0; i < n; i++)
		if (s[i] == 'e')
			e.push_back(i);
	if (e.empty())
		return cout << 0 << endl, 0;
	int m = e.size();
	memset(dp, 63, sizeof dp);
	dp[0][0] = 0;
	for (int i = 0; i < m; i++){
		memset(pd, 63, sizeof pd);
		for (int j = 0; j <= i; j++){
			if (j > 0)
				pd[e[j-1]+1] = dp[i][j];
			else
				pd[0] = dp[i][j];
		}
		for (int j = 0; j < n; j++)
			for (int c = 0; c < 10; c++)
				if (nex[j][c] != j)
					pd[nex[j][c]] = min(pd[nex[j][c]], pd[j] + 2);
		int it = 0;
		for (int idx = 0; idx < n; idx ++){
			if (s[idx] == 'e')
				continue;
			while (it < m and e[it] < idx)
				it ++;
			if (it <= i)
				continue;
			dp[it][i+1] = min(dp[it][i+1], pd[idx] + (idx-e[i]) + (it-i));
		}
	}
	int answer = 4*n;
	for (int i = 1; i <= m; i++)
		answer = min(answer, dp[m][i]);
	cout << answer << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 122 ms 192760 KB Output is correct
2 Correct 123 ms 192760 KB Output is correct
3 Correct 120 ms 192760 KB Output is correct
4 Correct 123 ms 192760 KB Output is correct
5 Correct 103 ms 192760 KB Output is correct
6 Correct 108 ms 192760 KB Output is correct
7 Correct 108 ms 192760 KB Output is correct
8 Correct 102 ms 192632 KB Output is correct
9 Correct 101 ms 192632 KB Output is correct
10 Correct 102 ms 192632 KB Output is correct
11 Correct 100 ms 192636 KB Output is correct
12 Correct 107 ms 192760 KB Output is correct
13 Correct 108 ms 192760 KB Output is correct
14 Correct 102 ms 192760 KB Output is correct
15 Correct 116 ms 192760 KB Output is correct
16 Correct 105 ms 192760 KB Output is correct
17 Correct 106 ms 192760 KB Output is correct
18 Correct 103 ms 192888 KB Output is correct
19 Correct 106 ms 192760 KB Output is correct
20 Correct 104 ms 192760 KB Output is correct
21 Correct 113 ms 192736 KB Output is correct
22 Correct 106 ms 192760 KB Output is correct
23 Correct 109 ms 192760 KB Output is correct
24 Correct 102 ms 192760 KB Output is correct
25 Correct 143 ms 192760 KB Output is correct
26 Correct 104 ms 192764 KB Output is correct
27 Correct 104 ms 192692 KB Output is correct
28 Correct 113 ms 192760 KB Output is correct
29 Correct 117 ms 192760 KB Output is correct
30 Correct 115 ms 192704 KB Output is correct
31 Correct 115 ms 192760 KB Output is correct
32 Correct 112 ms 192760 KB Output is correct
33 Correct 116 ms 192760 KB Output is correct
34 Correct 115 ms 192760 KB Output is correct
35 Correct 109 ms 192884 KB Output is correct
36 Correct 119 ms 192760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 670 ms 193160 KB Output isn't correct
2 Correct 535 ms 193144 KB Output is correct
3 Incorrect 261 ms 193016 KB Output isn't correct
4 Incorrect 666 ms 193016 KB Output isn't correct
5 Correct 501 ms 193016 KB Output is correct
6 Correct 364 ms 192888 KB Output is correct
7 Incorrect 570 ms 193060 KB Output isn't correct
8 Incorrect 584 ms 193144 KB Output isn't correct
9 Correct 536 ms 193144 KB Output is correct
10 Correct 484 ms 193016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 9 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 9 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 10 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 11 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 8 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 9 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 13 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 9 ms 956 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 8 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)