# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
503337 |
2022-01-07T16:47:43 Z |
qwerasdfzxcl |
Vim (BOI13_vim) |
C++14 |
|
557 ms |
61592 KB |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int dp[5050][5050], nxt[10][5050], prv[5050];
vector<int> E, pos;
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
string a;
cin >> n >> a;
if (n>5000) {printf("0\n"); return 0;}
string::iterator s = a.begin()-1;
int pt[10] = {0};
E.push_back(0);
for (int i=1;i<=n;i++){
if (s[i]=='e'){
E.push_back(i);
prv[i] = (int)E.size()-1;
}
else{
while(pos.size()<E.size()) pos.push_back(i);
prv[i] = prv[i-1];
for (int j=pt[s[i]-'a'];j<i;j++) nxt[s[i]-'a'][j] = i;
pt[s[i]-'a'] = i;
}
}
for (int j=0;j<10;j++){
for (int i=pt[j];i<=n;i++) nxt[j][i] = 1e9;
//for (int i=1;i<=n;i++) printf("%d ", nxt[j][i]);
//printf("\n");
}
/*for (auto &x:E) printf("%d ", x);
printf("\n");
for (auto &x:pos) printf("%d ", x);
printf("\n");
for (int i=1;i<=n;i++) printf("%d ", prv[i]);
printf("\n");*/
if (E.empty()){
printf("0\n"); return 0;
}
for (int i=0;i<(int)E.size();i++){
fill(dp[i], dp[i]+n+1, 1e9);
}
dp[0][1] = 0;
for (int i=0;i<(int)E.size();i++){
for (int j=1;j<=n;j++){
for (int k=0;k<10;k++){
int idx = nxt[k][j];
if (idx==1e9 || prv[idx]<i) continue;
if (prv[idx]!=i) dp[prv[idx]][pos[i+1]] = min(dp[prv[idx]][pos[i+1]], dp[i][j] + (idx - E[i+1]) + (prv[idx] - i) + 2);
else dp[i][idx] = min(dp[i][idx], dp[i][j] + 2);
}
}
}
//printf("%d\n", nxt[3][pos[0]]);
//printf("%d\n", dp[0][0] + (6 - E[0]));
int ans = 1e9;
for (int j=1;j<=n;j++) ans = min(ans, dp[(int)E.size()-1][j]);
printf("%d\n", ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1988 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1332 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
1212 KB |
Output isn't correct |
4 |
Correct |
4 ms |
1216 KB |
Output is correct |
5 |
Correct |
3 ms |
1340 KB |
Output is correct |
6 |
Correct |
5 ms |
1708 KB |
Output is correct |
7 |
Correct |
4 ms |
1612 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
1996 KB |
Output is correct |
14 |
Incorrect |
2 ms |
1356 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
1220 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
1340 KB |
Output isn't correct |
17 |
Correct |
3 ms |
1228 KB |
Output is correct |
18 |
Correct |
2 ms |
1228 KB |
Output is correct |
19 |
Incorrect |
2 ms |
1228 KB |
Output isn't correct |
20 |
Correct |
3 ms |
1228 KB |
Output is correct |
21 |
Correct |
3 ms |
1328 KB |
Output is correct |
22 |
Correct |
4 ms |
1356 KB |
Output is correct |
23 |
Correct |
2 ms |
956 KB |
Output is correct |
24 |
Correct |
3 ms |
972 KB |
Output is correct |
25 |
Correct |
2 ms |
972 KB |
Output is correct |
26 |
Correct |
3 ms |
1100 KB |
Output is correct |
27 |
Correct |
4 ms |
1520 KB |
Output is correct |
28 |
Correct |
5 ms |
1740 KB |
Output is correct |
29 |
Incorrect |
4 ms |
1612 KB |
Output isn't correct |
30 |
Incorrect |
3 ms |
1160 KB |
Output isn't correct |
31 |
Correct |
3 ms |
972 KB |
Output is correct |
32 |
Incorrect |
3 ms |
1100 KB |
Output isn't correct |
33 |
Correct |
2 ms |
1100 KB |
Output is correct |
34 |
Correct |
4 ms |
1356 KB |
Output is correct |
35 |
Correct |
4 ms |
1612 KB |
Output is correct |
36 |
Correct |
4 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
548 ms |
61592 KB |
Output is correct |
2 |
Correct |
426 ms |
47108 KB |
Output is correct |
3 |
Correct |
154 ms |
22420 KB |
Output is correct |
4 |
Correct |
557 ms |
61516 KB |
Output is correct |
5 |
Incorrect |
394 ms |
43684 KB |
Output isn't correct |
6 |
Incorrect |
285 ms |
27596 KB |
Output isn't correct |
7 |
Incorrect |
438 ms |
52900 KB |
Output isn't correct |
8 |
Incorrect |
448 ms |
51204 KB |
Output isn't correct |
9 |
Correct |
425 ms |
47172 KB |
Output is correct |
10 |
Incorrect |
354 ms |
44108 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
452 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
472 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
392 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
452 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |