# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
248789 | mieszko11b | Vim (BOI13_vim) | C++14 | 663 ms | 205560 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n;
char c[70007];
int pre[70007];
int nxt[10][70007];
int dp[5007][5007]; // ostatni usuniety, pozycja kursora
int main() {
scanf("%d", &n);
scanf(" %s", c + 1);
int cnte = 0;
for(int i = 1 ; i <= n ; i++) {
if(c[i] == 'e')
pre[i] = i, cnte++;
else
pre[i] = pre[i - 1];
}
for(int i = n - 1 ; i >= 0 ; i--) {
for(char cc = 'a' ; cc <= 'j' ; cc++) {
if(c[i + 1] == cc)
nxt[cc - 'a'][i] = i + 1;
else
nxt[cc - 'a'][i] = nxt[cc - 'a'][i + 1];
}
}
for(int i = 0 ; i < 5005 ; i++)
for(int j = 0 ; j < 5005 ; j++)
dp[i][j] = 1e9;
dp[0][1] = cnte;
for(int i = 0 ; i < n ; i++) {
if(i == 0 || c[i] == 'e') {
for(int j = 1 ; j <= n ; j++) {
if(j < n) {
for(int k = 0 ; k < 10 ; k++)
if(k != 4 && nxt[k][j])
dp[i][nxt[k][j]] = min(dp[i][nxt[k][j]], dp[i][j] + 2);
}
if(pre[j] > i)
dp[pre[j]][nxt[4][i] + 1] = min(dp[pre[j]][nxt[4][i] + 1],
dp[i][j] + j - nxt[4][i]);
}
}
}
int res = 1e9;
for(int j = 1 ; j <= n ; j++)
res = min(res, dp[pre[n]][j]);
printf("%d\n", res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |