#include <bits/stdc++.h>
using namespace std;
const int mxN=7e4;
int n, ans=1e9, dp[mxN][10], nxt[mxN+1][10];
string s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s;
fill(nxt[n], nxt[n]+10, n);
for(int i=n-1; ~i; --i) {
memcpy(nxt[i], nxt[i+1], 40);
nxt[i][s[i]-'a']=i;
}
memset(dp, 0x3f, sizeof(dp));
dp[0][s[0]-'a']=0;
int e=n-1;
while(e&&s[e-1]^'e')
--e;
for(int i=0; i<n; ++i) {
for(int j=0; j<10; ++j) {
if(j==4)
continue;
if(nxt[i][j]>=e)
ans=min(dp[i][j], ans);
int y=n;
for(int k=0; k<10; ++k)
if(k^4)
y=min(nxt[nxt[nxt[i][j]][4]][k], y);
for(int k=0; k<10; ++k) {
int a=nxt[i+1][k], nf=1;
if(a<=nxt[i][j]) {
a=nxt[nxt[i][j]+1][k];
++nf;
}
if(k==4||a>=n)
continue;
int x=min(a, y);
dp[x][k]=min(dp[i][j]+2*nf+max(a-nxt[nxt[i][j]][4], 0), dp[x][k]);
}
}
}
for(char c : s)
ans+=c=='e';
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
4 |
Correct |
4 ms |
3072 KB |
Output is correct |
5 |
Correct |
4 ms |
3072 KB |
Output is correct |
6 |
Correct |
5 ms |
3072 KB |
Output is correct |
7 |
Correct |
4 ms |
3072 KB |
Output is correct |
8 |
Correct |
5 ms |
3072 KB |
Output is correct |
9 |
Correct |
2 ms |
3072 KB |
Output is correct |
10 |
Correct |
4 ms |
3072 KB |
Output is correct |
11 |
Correct |
5 ms |
3072 KB |
Output is correct |
12 |
Correct |
5 ms |
3072 KB |
Output is correct |
13 |
Correct |
4 ms |
3072 KB |
Output is correct |
14 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
15 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
16 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
17 |
Correct |
5 ms |
3072 KB |
Output is correct |
18 |
Correct |
5 ms |
3072 KB |
Output is correct |
19 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
20 |
Correct |
4 ms |
3072 KB |
Output is correct |
21 |
Correct |
5 ms |
3072 KB |
Output is correct |
22 |
Correct |
5 ms |
3072 KB |
Output is correct |
23 |
Correct |
4 ms |
3072 KB |
Output is correct |
24 |
Correct |
0 ms |
3072 KB |
Output is correct |
25 |
Correct |
5 ms |
3072 KB |
Output is correct |
26 |
Correct |
5 ms |
3120 KB |
Output is correct |
27 |
Correct |
5 ms |
3200 KB |
Output is correct |
28 |
Correct |
5 ms |
3072 KB |
Output is correct |
29 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
30 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
31 |
Correct |
5 ms |
3072 KB |
Output is correct |
32 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
33 |
Correct |
5 ms |
3072 KB |
Output is correct |
34 |
Correct |
5 ms |
3072 KB |
Output is correct |
35 |
Correct |
5 ms |
3072 KB |
Output is correct |
36 |
Correct |
5 ms |
3072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3328 KB |
Output is correct |
2 |
Correct |
8 ms |
3328 KB |
Output is correct |
3 |
Correct |
6 ms |
3200 KB |
Output is correct |
4 |
Correct |
7 ms |
3328 KB |
Output is correct |
5 |
Incorrect |
7 ms |
3328 KB |
Output isn't correct |
6 |
Incorrect |
7 ms |
3328 KB |
Output isn't correct |
7 |
Incorrect |
7 ms |
3328 KB |
Output isn't correct |
8 |
Incorrect |
8 ms |
3328 KB |
Output isn't correct |
9 |
Correct |
7 ms |
3328 KB |
Output is correct |
10 |
Incorrect |
8 ms |
3328 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
5632 KB |
Output isn't correct |
2 |
Incorrect |
35 ms |
5552 KB |
Output isn't correct |
3 |
Incorrect |
36 ms |
5504 KB |
Output isn't correct |
4 |
Incorrect |
37 ms |
6136 KB |
Output isn't correct |
5 |
Incorrect |
37 ms |
6016 KB |
Output isn't correct |
6 |
Incorrect |
36 ms |
5724 KB |
Output isn't correct |
7 |
Incorrect |
37 ms |
5760 KB |
Output isn't correct |
8 |
Incorrect |
33 ms |
5888 KB |
Output isn't correct |
9 |
Incorrect |
39 ms |
5760 KB |
Output isn't correct |
10 |
Incorrect |
40 ms |
5760 KB |
Output isn't correct |
11 |
Incorrect |
34 ms |
6016 KB |
Output isn't correct |
12 |
Incorrect |
38 ms |
6016 KB |
Output isn't correct |
13 |
Incorrect |
52 ms |
6008 KB |
Output isn't correct |
14 |
Incorrect |
40 ms |
5988 KB |
Output isn't correct |
15 |
Incorrect |
44 ms |
6016 KB |
Output isn't correct |
16 |
Incorrect |
42 ms |
5504 KB |
Output isn't correct |
17 |
Incorrect |
31 ms |
5504 KB |
Output isn't correct |
18 |
Incorrect |
32 ms |
5624 KB |
Output isn't correct |
19 |
Incorrect |
37 ms |
5624 KB |
Output isn't correct |
20 |
Incorrect |
50 ms |
5624 KB |
Output isn't correct |