#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[a+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 |
5 ms |
3072 KB |
Output is correct |
2 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
3 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
4 |
Correct |
4 ms |
3072 KB |
Output is correct |
5 |
Correct |
5 ms |
3104 KB |
Output is correct |
6 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
7 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
8 |
Correct |
4 ms |
3072 KB |
Output is correct |
9 |
Correct |
4 ms |
3200 KB |
Output is correct |
10 |
Correct |
5 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 |
5 ms |
3044 KB |
Output is correct |
14 |
Incorrect |
6 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 |
4 ms |
3072 KB |
Output is correct |
18 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
19 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
20 |
Correct |
5 ms |
3072 KB |
Output is correct |
21 |
Correct |
28 ms |
3072 KB |
Output is correct |
22 |
Correct |
5 ms |
3072 KB |
Output is correct |
23 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
24 |
Correct |
5 ms |
3072 KB |
Output is correct |
25 |
Correct |
4 ms |
3072 KB |
Output is correct |
26 |
Correct |
6 ms |
3072 KB |
Output is correct |
27 |
Correct |
5 ms |
3072 KB |
Output is correct |
28 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
29 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
30 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
31 |
Correct |
4 ms |
3072 KB |
Output is correct |
32 |
Incorrect |
4 ms |
3072 KB |
Output isn't correct |
33 |
Correct |
4 ms |
3072 KB |
Output is correct |
34 |
Correct |
6 ms |
3072 KB |
Output is correct |
35 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
36 |
Incorrect |
5 ms |
3072 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
3328 KB |
Output isn't correct |
2 |
Incorrect |
7 ms |
3328 KB |
Output isn't correct |
3 |
Incorrect |
6 ms |
3200 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
3328 KB |
Output isn't 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 |
7 ms |
3200 KB |
Output isn't correct |
9 |
Incorrect |
7 ms |
3328 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
3328 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
5724 KB |
Output isn't correct |
2 |
Incorrect |
37 ms |
5596 KB |
Output isn't correct |
3 |
Incorrect |
37 ms |
5504 KB |
Output isn't correct |
4 |
Incorrect |
36 ms |
6016 KB |
Output isn't correct |
5 |
Incorrect |
42 ms |
6016 KB |
Output isn't correct |
6 |
Incorrect |
52 ms |
5632 KB |
Output isn't correct |
7 |
Incorrect |
35 ms |
5760 KB |
Output isn't correct |
8 |
Incorrect |
33 ms |
5880 KB |
Output isn't correct |
9 |
Incorrect |
35 ms |
5760 KB |
Output isn't correct |
10 |
Incorrect |
45 ms |
5760 KB |
Output isn't correct |
11 |
Incorrect |
38 ms |
6016 KB |
Output isn't correct |
12 |
Incorrect |
39 ms |
6016 KB |
Output isn't correct |
13 |
Incorrect |
38 ms |
5888 KB |
Output isn't correct |
14 |
Incorrect |
42 ms |
6016 KB |
Output isn't correct |
15 |
Incorrect |
48 ms |
6016 KB |
Output isn't correct |
16 |
Incorrect |
28 ms |
5504 KB |
Output isn't correct |
17 |
Incorrect |
34 ms |
5632 KB |
Output isn't correct |
18 |
Incorrect |
34 ms |
5620 KB |
Output isn't correct |
19 |
Incorrect |
43 ms |
5504 KB |
Output isn't correct |
20 |
Incorrect |
38 ms |
5504 KB |
Output isn't correct |