Submission #256289

# Submission time Handle Problem Language Result Execution time Memory
256289 2020-08-02T13:49:41 Z amoo_safar Vim (BOI13_vim) C++17
50 / 100
5 ms 2816 KB
// Zende bad Shoma nasime faghat !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 5e2 + 10;
const int Inf = 1e9;
const ll Log = 30;

str s;
int dp[N][N];
int nx[N][12], nxe[N], ps[N], ps2[N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n >> s;


	memset(nx, -1, sizeof nx);
	nxe[n - 1] = n - 1;
	for(int i = n - 2; i >= 0; i--){
		for(int j = 0; j < 10; j++) nx[i][j] = nx[i + 1][j];
		nx[i][s[i + 1] - 'a'] = i + 1;
		nxe[i] = (s[i] == 'e' ? nxe[i + 1] : i);
	}

	vector<int> E;
	ps2[0] = 1;
	for(int i = 1; i < n; i++){
		if(s[i] == 'e') E.pb(i);
		ps[i] = ps[i - 1] + (s[i] == 'e' ? 1 : 0);
		ps2[i] = ps2[i - 1] + (s[i] == 'e' ? 0 : 1);
	}

	int ce = E.size();

	memset(dp, 31, sizeof dp);
	dp[0][0] = 0;
	for(int j = 0; j < ce; j++){
		
		for(int i = 0; i < n; i++){
			if(s[i] == 'e') continue;

			for(int c = 0; c < 10; c++){
				if(nx[i][c] != -1) dp[nx[i][c]][j] = min(dp[nx[i][c]][j], dp[i][j] + 2);
			}
			if(E[j] < i){
				dp[ nxe[E[j]] ][ps[i]] = min(dp[ nxe[E[j]] ][ps[i]], dp[i][j] + ps2[i] - ps2[nxe[E[j]]]);
			}
		}
	}
	int ans = Inf;
	for(int i = 0; i < n; i++){
		ans = min(ans, dp[i][ce] + ce + ce);
	}
	//debug(dp[3][2]);
	//debug(nx[3][5]);
	//debug(dp[9][2]);

	cout << ans << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1408 KB Output is correct
2 Correct 3 ms 1408 KB Output is correct
3 Correct 2 ms 1408 KB Output is correct
4 Correct 3 ms 1408 KB Output is correct
5 Correct 3 ms 1408 KB Output is correct
6 Correct 5 ms 1408 KB Output is correct
7 Correct 4 ms 1408 KB Output is correct
8 Correct 1 ms 1408 KB Output is correct
9 Correct 1 ms 1408 KB Output is correct
10 Correct 2 ms 1408 KB Output is correct
11 Correct 1 ms 1408 KB Output is correct
12 Correct 1 ms 1408 KB Output is correct
13 Correct 5 ms 1408 KB Output is correct
14 Correct 3 ms 1408 KB Output is correct
15 Correct 3 ms 1408 KB Output is correct
16 Correct 3 ms 1408 KB Output is correct
17 Correct 4 ms 1408 KB Output is correct
18 Correct 3 ms 1408 KB Output is correct
19 Correct 3 ms 1408 KB Output is correct
20 Correct 3 ms 1408 KB Output is correct
21 Correct 3 ms 1408 KB Output is correct
22 Correct 3 ms 1408 KB Output is correct
23 Correct 3 ms 1408 KB Output is correct
24 Correct 4 ms 1408 KB Output is correct
25 Correct 3 ms 1408 KB Output is correct
26 Correct 4 ms 1408 KB Output is correct
27 Correct 4 ms 1408 KB Output is correct
28 Correct 4 ms 1408 KB Output is correct
29 Correct 4 ms 1408 KB Output is correct
30 Correct 3 ms 1408 KB Output is correct
31 Correct 3 ms 1408 KB Output is correct
32 Correct 3 ms 1408 KB Output is correct
33 Correct 3 ms 1408 KB Output is correct
34 Correct 4 ms 1408 KB Output is correct
35 Correct 4 ms 1408 KB Output is correct
36 Correct 4 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 3 ms 2688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 3 ms 2688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 3 ms 2688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 3 ms 2816 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 3 ms 2688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 2748 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 3 ms 2688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 4 ms 2688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 3 ms 2688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 1 ms 768 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 1 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 2 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 1 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 2 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 2 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 2 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 2 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 2 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 2 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 1 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 1 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 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)