답안 #256383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256383 2020-08-02T15:51:26 Z Saboon Vim (BOI13_vim) C++14
13.8889 / 100
45 ms 1440 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 = 500 + 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 j = 0; j <= m; j++){
		memset(pd, 63, sizeof pd);
		if (j > 0)
			pd[e[j-1]] = 0;
		else
			pd[0] = 0;
		for (int i = 0; i < n; i++)
			for (int c = 0; c < 10; c++)
				if (nex[i][c] != i)
					pd[nex[i][c]] = min(pd[nex[i][c]], pd[i] + 2);

		for (int i = j; i <= m; i++){
			int it = i;
			int idx = (j == 0 ? 0 : e[j-1]);
			for (; idx < n; idx ++){
				while (it < m and e[it] < idx)
					it ++;
				if (it == i)
					continue;
				dp[it][i+1] = min(dp[it][i+1], dp[i][j] + 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 1408 KB Output is correct
2 Incorrect 16 ms 1408 KB Output isn't correct
3 Incorrect 12 ms 1408 KB Output isn't correct
4 Incorrect 15 ms 1408 KB Output isn't correct
5 Correct 17 ms 1408 KB Output is correct
6 Incorrect 31 ms 1408 KB Output isn't correct
7 Incorrect 37 ms 1408 KB Output isn't correct
8 Correct 1 ms 1408 KB Output is correct
9 Correct 1 ms 1408 KB Output is correct
10 Incorrect 2 ms 1408 KB Output isn't correct
11 Correct 1 ms 1408 KB Output is correct
12 Correct 2 ms 1408 KB Output is correct
13 Correct 45 ms 1408 KB Output is correct
14 Incorrect 16 ms 1408 KB Output isn't correct
15 Incorrect 17 ms 1408 KB Output isn't correct
16 Incorrect 16 ms 1408 KB Output isn't correct
17 Incorrect 14 ms 1408 KB Output isn't correct
18 Incorrect 13 ms 1408 KB Output isn't correct
19 Correct 13 ms 1408 KB Output is correct
20 Correct 14 ms 1408 KB Output is correct
21 Incorrect 15 ms 1408 KB Output isn't correct
22 Correct 16 ms 1408 KB Output is correct
23 Incorrect 7 ms 1408 KB Output isn't correct
24 Incorrect 8 ms 1408 KB Output isn't correct
25 Incorrect 8 ms 1440 KB Output isn't correct
26 Incorrect 10 ms 1280 KB Output isn't correct
27 Incorrect 23 ms 1408 KB Output isn't correct
28 Incorrect 29 ms 1408 KB Output isn't correct
29 Incorrect 25 ms 1408 KB Output isn't correct
30 Incorrect 11 ms 1408 KB Output isn't correct
31 Incorrect 8 ms 1408 KB Output isn't correct
32 Incorrect 9 ms 1408 KB Output isn't correct
33 Incorrect 14 ms 1408 KB Output isn't correct
34 Incorrect 18 ms 1408 KB Output isn't correct
35 Incorrect 23 ms 1408 KB Output isn't correct
36 Incorrect 27 ms 1408 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 2 ms 1280 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 2 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 1 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 1 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 1 ms 872 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 3 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 1 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 2 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 2 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 1 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 1 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)