Submission #256375

# Submission time Handle Problem Language Result Execution time Memory
256375 2020-08-02T15:48:02 Z shayan_p Vim (BOI13_vim) C++14
75.6111 / 100
2000 ms 325788 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 = 70010, mod = 1e9 + 7, inf = 1e9 + 10;

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

unordered_map<int, int> dp[maxn];
vector<int> poses;

int solve(int i, int j){
    if(i >= sz(poses))
	return 0;
    if(nxt[ poses[i] ][8] + 100 < j)
	return inf;
    if(dp[i].count(j))
	return dp[i][j];
    int ans = inf;
    if(j >= poses[i])
	ans =  j - poses[i] + solve( upper_bound(poses.begin(), poses.end(), j) - poses.begin(), poses[i] );
    int pt = lower_bound(nxt[j], nxt[j] + 10, poses[i]) - nxt[j];
    for(int w = 8 ; w >= 0 && nxt[j][w] != j && w >= pt-1; w--)
	ans = min(ans, 2 + solve(i, nxt[j][w]));
    return dp[i][j] = ans;
}

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;
    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--){
	for(int j = 0; j < 9; j++)
	    nxt[i][j] = (lst[j] == -1 ? i : lst[j]);
	sort(nxt[i], nxt[i] + 9);
	nxt[i][9] = inf;
	int id = (s[i] - 'a') - (s[i] > 'e');
	lst[id] = i;
    }
    ans+= solve(0, 0);
    return cout << ans << "\n", 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8320 KB Output is correct
2 Correct 11 ms 8320 KB Output is correct
3 Correct 8 ms 7552 KB Output is correct
4 Correct 12 ms 8320 KB Output is correct
5 Correct 14 ms 8448 KB Output is correct
6 Correct 15 ms 8704 KB Output is correct
7 Correct 18 ms 8576 KB Output is correct
8 Correct 4 ms 6912 KB Output is correct
9 Correct 4 ms 6912 KB Output is correct
10 Correct 4 ms 6912 KB Output is correct
11 Correct 4 ms 6912 KB Output is correct
12 Correct 4 ms 6912 KB Output is correct
13 Correct 13 ms 8192 KB Output is correct
14 Correct 12 ms 8320 KB Output is correct
15 Correct 8 ms 7680 KB Output is correct
16 Correct 13 ms 8320 KB Output is correct
17 Correct 12 ms 8064 KB Output is correct
18 Correct 11 ms 8064 KB Output is correct
19 Incorrect 11 ms 8332 KB Output isn't correct
20 Correct 13 ms 8320 KB Output is correct
21 Correct 12 ms 8320 KB Output is correct
22 Correct 13 ms 8448 KB Output is correct
23 Correct 9 ms 7808 KB Output is correct
24 Correct 13 ms 7936 KB Output is correct
25 Correct 10 ms 7680 KB Output is correct
26 Correct 9 ms 7680 KB Output is correct
27 Correct 12 ms 8320 KB Output is correct
28 Correct 14 ms 8704 KB Output is correct
29 Correct 14 ms 8704 KB Output is correct
30 Correct 11 ms 8064 KB Output is correct
31 Correct 10 ms 7808 KB Output is correct
32 Correct 9 ms 7808 KB Output is correct
33 Correct 10 ms 7808 KB Output is correct
34 Correct 12 ms 8192 KB Output is correct
35 Correct 14 ms 8576 KB Output is correct
36 Correct 17 ms 8704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 22264 KB Output is correct
2 Correct 160 ms 30456 KB Output is correct
3 Correct 69 ms 15992 KB Output is correct
4 Correct 109 ms 22272 KB Output is correct
5 Correct 257 ms 40952 KB Output is correct
6 Correct 859 ms 99076 KB Output is correct
7 Correct 214 ms 36472 KB Output is correct
8 Correct 122 ms 23800 KB Output is correct
9 Correct 162 ms 30456 KB Output is correct
10 Incorrect 178 ms 30712 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2097 ms 246712 KB Time limit exceeded
2 Correct 925 ms 143096 KB Output is correct
3 Correct 972 ms 149368 KB Output is correct
4 Execution timed out 2085 ms 325788 KB Time limit exceeded
5 Execution timed out 2096 ms 242564 KB Time limit exceeded
6 Incorrect 1394 ms 208288 KB Output isn't correct
7 Execution timed out 2096 ms 300532 KB Time limit exceeded
8 Execution timed out 2089 ms 255048 KB Time limit exceeded
9 Execution timed out 2085 ms 291544 KB Time limit exceeded
10 Correct 1762 ms 242872 KB Output is correct
11 Execution timed out 2096 ms 325752 KB Time limit exceeded
12 Execution timed out 2097 ms 259148 KB Time limit exceeded
13 Correct 1140 ms 165344 KB Output is correct
14 Correct 1026 ms 164368 KB Output is correct
15 Correct 1822 ms 267968 KB Output is correct
16 Execution timed out 2094 ms 286328 KB Time limit exceeded
17 Execution timed out 2085 ms 215980 KB Time limit exceeded
18 Correct 1052 ms 149348 KB Output is correct
19 Correct 991 ms 142968 KB Output is correct
20 Correct 1717 ms 232928 KB Output is correct