# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
256337 |
2020-08-02T14:43:00 Z |
shayan_p |
Vim (BOI13_vim) |
C++14 |
|
362 ms |
33052 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];
map<pii, int> 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}];
if(j >= poses[i])
return dp[{i, j}] = j - poses[i] + solve( upper_bound(poses.begin(), poses.end(), j) - poses.begin(), poses[i] );
int ans = inf;
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 |
3 ms |
3200 KB |
Output is correct |
2 |
Incorrect |
3 ms |
3200 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
3200 KB |
Output isn't correct |
4 |
Correct |
3 ms |
3200 KB |
Output is correct |
5 |
Correct |
4 ms |
3328 KB |
Output is correct |
6 |
Correct |
4 ms |
3328 KB |
Output is correct |
7 |
Correct |
4 ms |
3200 KB |
Output is correct |
8 |
Correct |
2 ms |
3072 KB |
Output is correct |
9 |
Correct |
2 ms |
3072 KB |
Output is correct |
10 |
Correct |
2 ms |
3072 KB |
Output is correct |
11 |
Correct |
2 ms |
3072 KB |
Output is correct |
12 |
Correct |
2 ms |
3072 KB |
Output is correct |
13 |
Correct |
3 ms |
3200 KB |
Output is correct |
14 |
Incorrect |
3 ms |
3200 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
3200 KB |
Output isn't correct |
16 |
Incorrect |
3 ms |
3200 KB |
Output isn't correct |
17 |
Correct |
3 ms |
3200 KB |
Output is correct |
18 |
Correct |
3 ms |
3200 KB |
Output is correct |
19 |
Incorrect |
3 ms |
3200 KB |
Output isn't correct |
20 |
Correct |
3 ms |
3200 KB |
Output is correct |
21 |
Correct |
4 ms |
3200 KB |
Output is correct |
22 |
Correct |
4 ms |
3200 KB |
Output is correct |
23 |
Correct |
4 ms |
3200 KB |
Output is correct |
24 |
Correct |
3 ms |
3200 KB |
Output is correct |
25 |
Correct |
3 ms |
3200 KB |
Output is correct |
26 |
Correct |
3 ms |
3200 KB |
Output is correct |
27 |
Correct |
4 ms |
3200 KB |
Output is correct |
28 |
Correct |
5 ms |
3200 KB |
Output is correct |
29 |
Incorrect |
4 ms |
3200 KB |
Output isn't correct |
30 |
Incorrect |
3 ms |
3200 KB |
Output isn't correct |
31 |
Correct |
3 ms |
3200 KB |
Output is correct |
32 |
Incorrect |
3 ms |
3200 KB |
Output isn't correct |
33 |
Correct |
3 ms |
3328 KB |
Output is correct |
34 |
Correct |
4 ms |
3200 KB |
Output is correct |
35 |
Correct |
4 ms |
3328 KB |
Output is correct |
36 |
Correct |
4 ms |
3328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
4736 KB |
Output is correct |
2 |
Correct |
32 ms |
5752 KB |
Output is correct |
3 |
Correct |
12 ms |
4096 KB |
Output is correct |
4 |
Correct |
19 ms |
4736 KB |
Output is correct |
5 |
Incorrect |
30 ms |
5496 KB |
Output isn't correct |
6 |
Incorrect |
16 ms |
4608 KB |
Output isn't correct |
7 |
Incorrect |
18 ms |
4736 KB |
Output isn't correct |
8 |
Incorrect |
20 ms |
4736 KB |
Output isn't correct |
9 |
Correct |
31 ms |
5752 KB |
Output is correct |
10 |
Incorrect |
25 ms |
5248 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
196 ms |
19704 KB |
Output isn't correct |
2 |
Incorrect |
136 ms |
16888 KB |
Output isn't correct |
3 |
Incorrect |
160 ms |
17528 KB |
Output isn't correct |
4 |
Incorrect |
210 ms |
23032 KB |
Output isn't correct |
5 |
Incorrect |
249 ms |
23288 KB |
Output isn't correct |
6 |
Incorrect |
255 ms |
23928 KB |
Output isn't correct |
7 |
Incorrect |
338 ms |
30840 KB |
Output isn't correct |
8 |
Incorrect |
281 ms |
26004 KB |
Output isn't correct |
9 |
Incorrect |
277 ms |
25336 KB |
Output isn't correct |
10 |
Incorrect |
279 ms |
25976 KB |
Output isn't correct |
11 |
Incorrect |
217 ms |
22972 KB |
Output isn't correct |
12 |
Incorrect |
257 ms |
23288 KB |
Output isn't correct |
13 |
Incorrect |
210 ms |
19320 KB |
Output isn't correct |
14 |
Incorrect |
163 ms |
19192 KB |
Output isn't correct |
15 |
Incorrect |
362 ms |
33052 KB |
Output isn't correct |
16 |
Incorrect |
141 ms |
16120 KB |
Output isn't correct |
17 |
Incorrect |
194 ms |
19832 KB |
Output isn't correct |
18 |
Incorrect |
154 ms |
17528 KB |
Output isn't correct |
19 |
Incorrect |
142 ms |
16888 KB |
Output isn't correct |
20 |
Incorrect |
322 ms |
29048 KB |
Output isn't correct |