# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
256391 |
2020-08-02T16:02:09 Z |
shayan_p |
Vim (BOI13_vim) |
C++14 |
|
2000 ms |
524292 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)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
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];
struct Hash{
int operator() (const pii &p)const{
return hash<ll>()( 1ll * p.F * maxn + p.S );
}
};
unordered_map<pii, int, Hash> dp;
vector<int> poses;
int solve(int i, int j){
if(i >= sz(poses))
return 0;
if(dp.count({i, 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] );
if(nxt[ poses[i] ][8] < j)
return dp[{i, j}] = ans;
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();
dp.reserve(1<<17);
dp.max_load_factor(0.25);
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 |
9 ms |
5120 KB |
Output is correct |
2 |
Correct |
5 ms |
4864 KB |
Output is correct |
3 |
Correct |
4 ms |
4608 KB |
Output is correct |
4 |
Correct |
6 ms |
4736 KB |
Output is correct |
5 |
Correct |
10 ms |
5632 KB |
Output is correct |
6 |
Correct |
6 ms |
4864 KB |
Output is correct |
7 |
Correct |
7 ms |
4864 KB |
Output is correct |
8 |
Correct |
2 ms |
4096 KB |
Output is correct |
9 |
Correct |
2 ms |
4096 KB |
Output is correct |
10 |
Correct |
2 ms |
4096 KB |
Output is correct |
11 |
Correct |
2 ms |
4096 KB |
Output is correct |
12 |
Correct |
2 ms |
4096 KB |
Output is correct |
13 |
Correct |
8 ms |
5120 KB |
Output is correct |
14 |
Correct |
6 ms |
4864 KB |
Output is correct |
15 |
Correct |
5 ms |
4608 KB |
Output is correct |
16 |
Correct |
6 ms |
4736 KB |
Output is correct |
17 |
Correct |
6 ms |
4768 KB |
Output is correct |
18 |
Correct |
5 ms |
4608 KB |
Output is correct |
19 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
20 |
Correct |
7 ms |
4992 KB |
Output is correct |
21 |
Correct |
7 ms |
4736 KB |
Output is correct |
22 |
Correct |
12 ms |
5632 KB |
Output is correct |
23 |
Correct |
8 ms |
4864 KB |
Output is correct |
24 |
Correct |
7 ms |
4864 KB |
Output is correct |
25 |
Correct |
5 ms |
4608 KB |
Output is correct |
26 |
Correct |
5 ms |
4480 KB |
Output is correct |
27 |
Correct |
7 ms |
4608 KB |
Output is correct |
28 |
Correct |
6 ms |
4864 KB |
Output is correct |
29 |
Incorrect |
8 ms |
4864 KB |
Output isn't correct |
30 |
Correct |
6 ms |
4736 KB |
Output is correct |
31 |
Correct |
5 ms |
4608 KB |
Output is correct |
32 |
Correct |
4 ms |
4480 KB |
Output is correct |
33 |
Correct |
6 ms |
4480 KB |
Output is correct |
34 |
Correct |
5 ms |
4608 KB |
Output is correct |
35 |
Correct |
9 ms |
4736 KB |
Output is correct |
36 |
Correct |
7 ms |
4864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
13536 KB |
Output is correct |
2 |
Correct |
55 ms |
23088 KB |
Output is correct |
3 |
Correct |
38 ms |
12884 KB |
Output is correct |
4 |
Correct |
43 ms |
13436 KB |
Output is correct |
5 |
Correct |
171 ms |
43848 KB |
Output is correct |
6 |
Correct |
788 ms |
170304 KB |
Output is correct |
7 |
Correct |
163 ms |
43668 KB |
Output is correct |
8 |
Correct |
67 ms |
23124 KB |
Output is correct |
9 |
Correct |
65 ms |
23124 KB |
Output is correct |
10 |
Incorrect |
69 ms |
23120 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1917 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Correct |
313 ms |
85920 KB |
Output is correct |
3 |
Correct |
502 ms |
170792 KB |
Output is correct |
4 |
Runtime error |
1767 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Runtime error |
1914 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Incorrect |
565 ms |
170556 KB |
Output isn't correct |
7 |
Runtime error |
1957 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
2043 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
1791 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Correct |
968 ms |
343016 KB |
Output is correct |
11 |
Runtime error |
1728 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
12 |
Runtime error |
1989 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
13 |
Correct |
628 ms |
170792 KB |
Output is correct |
14 |
Correct |
426 ms |
86052 KB |
Output is correct |
15 |
Correct |
603 ms |
171052 KB |
Output is correct |
16 |
Execution timed out |
2124 ms |
524292 KB |
Time limit exceeded |
17 |
Execution timed out |
2128 ms |
364132 KB |
Time limit exceeded |
18 |
Correct |
492 ms |
170536 KB |
Output is correct |
19 |
Correct |
318 ms |
85924 KB |
Output is correct |
20 |
Correct |
491 ms |
170924 KB |
Output is correct |