Submission #256278

# Submission time Handle Problem Language Result Execution time Memory
256278 2020-08-02T13:25:14 Z shayan_p Vim (BOI13_vim) C++14
60 / 100
240 ms 34384 KB
// And you curse yourself for things you never done

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 5010, mod = 1e9 + 7, inf = 1e9 + 10;

int dp[maxn][maxn];
int nxt[maxn][10], lst[10];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    int n;
    cin >> n;
    string _s, s;
    cin >> _s;
    int ans = 0;
    vector<int> poses;
    for(int i = 0; i < n; i++){
	if(_s[i] == 'e')
	    ans+= 2;
	if(_s[i] == 'e' && _s[i + 1] != 'e')
	    poses.PB(sz(s));
	if(_s[i] != 'e')
	    s+= _s[i];	
    }
    memset(lst, -1, sizeof lst);
    memset(nxt, -1, sizeof nxt);
    n = sz(s);
    for(int i = n-1; i >= 0; i--){
	memcpy(nxt[i], lst, sizeof lst);
	int id = (s[i] - 'a') - (s[i] > 'e');
	lst[id] = i;
    }
    for(int i = sz(poses)-1; i >= 0; i--){
	int pt = sz(poses)-1;
	for(int j = n-1; j >= 0; j--){
	    dp[i][j] = inf;
	    if(pt >= i)
		dp[i][j] = j - poses[i] + dp[pt + 1][poses[i]];
	    for(int k = 0; k < 9; k++)
		if(nxt[j][k] != -1)
		    dp[i][j] = min(dp[i][j], 2 + dp[i][nxt[j][k]]);	    
	    if(poses[pt] == j)
		pt--;
	}
    }
    ans+= dp[0][0];
    return cout << ans << "\n", 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1280 KB Output is correct
2 Correct 2 ms 1408 KB Output is correct
3 Correct 2 ms 1152 KB Output is correct
4 Correct 2 ms 1408 KB Output is correct
5 Correct 2 ms 1408 KB Output is correct
6 Correct 3 ms 1664 KB Output is correct
7 Correct 3 ms 1664 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 0 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 2 ms 1280 KB Output is correct
14 Correct 2 ms 1408 KB Output is correct
15 Correct 1 ms 1152 KB Output is correct
16 Correct 2 ms 1408 KB Output is correct
17 Correct 2 ms 1280 KB Output is correct
18 Correct 2 ms 1280 KB Output is correct
19 Correct 1 ms 1280 KB Output is correct
20 Correct 2 ms 1280 KB Output is correct
21 Correct 2 ms 1408 KB Output is correct
22 Correct 2 ms 1408 KB Output is correct
23 Correct 2 ms 1152 KB Output is correct
24 Correct 2 ms 1024 KB Output is correct
25 Correct 2 ms 1152 KB Output is correct
26 Correct 2 ms 1280 KB Output is correct
27 Correct 2 ms 1536 KB Output is correct
28 Correct 3 ms 1664 KB Output is correct
29 Correct 2 ms 1664 KB Output is correct
30 Correct 2 ms 1280 KB Output is correct
31 Correct 2 ms 1152 KB Output is correct
32 Correct 2 ms 1152 KB Output is correct
33 Correct 2 ms 1280 KB Output is correct
34 Correct 2 ms 1408 KB Output is correct
35 Correct 2 ms 1536 KB Output is correct
36 Correct 2 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 17376 KB Output is correct
2 Correct 240 ms 34368 KB Output is correct
3 Correct 40 ms 8696 KB Output is correct
4 Correct 93 ms 17528 KB Output is correct
5 Correct 212 ms 32888 KB Output is correct
6 Correct 155 ms 25340 KB Output is correct
7 Correct 117 ms 21156 KB Output is correct
8 Correct 121 ms 20728 KB Output is correct
9 Correct 220 ms 34384 KB Output is correct
10 Correct 211 ms 33528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 4608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 8 ms 4608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 9 ms 4608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 9 ms 4864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 7 ms 2944 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 9 ms 4352 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 9 ms 4736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 11 ms 3712 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 8 ms 3584 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 9 ms 4864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 12 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 9 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 8 ms 4608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 9 ms 4608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 9 ms 4608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 9 ms 4608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 11 ms 4608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 9 ms 4020 KB Execution killed with signal 11 (could be triggered by violating memory limits)