Submission #242933

# Submission time Handle Problem Language Result Execution time Memory
242933 2020-06-29T21:07:10 Z Bruteforceman Vim (BOI13_vim) C++11
42.5 / 100
625 ms 27640 KB
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
const int maxn = 7e4 + 10;
const int alpha = 10;
string s;
int n;
int nxt[alpha][maxn];
int opt[maxn];
map <pair <int, int>, int> mem;
int cnt[maxn];

int dp(int now, int done) {
  int jump = opt[done];
  if(jump == n) return 0;
  if(mem.find(make_pair(now, done)) != mem.end()) {
    return mem[make_pair(now, done)];
  }
  int ans = inf;
  for(int i = 0; i < alpha; i++) {
    if(i != 'e' - 'a' && nxt[i][now] < n) {
      int idx = nxt[i][now];
      if(idx < jump) {
        ans = min(ans, 2 + dp(idx, max(done, idx)));
      } else {
        ans = min(ans, 2 + dp(jump, idx) + cnt[idx] - cnt[jump]);
      }
    }
  }
  return mem[make_pair(now, done)] = ans;
}
int main() {
  cin >> n >> s;
  vector <int> aux (alpha, n);
  for(int i = n - 1; i >= 0; i--) {
    for(int j = 0; j < alpha; j++) {
      nxt[j][i] = aux[j];
    }
    aux[s[i] - 'a'] = i;
  }
  int var = n;
  for(int i = n - 1; i >= 0; i--) {
    opt[i] = var;
    if(i > 0 && s[i - 1] == 'e' && s[i] != 'e') {
      var = i;
    }
  }
  int total = 0;
  for(int i = 0; i < n; i++) {
    total += (s[i] != 'e');
    cnt[i] = total;
  }
  int ans = 2 * count(s.begin(), s.end(), 'e');
  cout << ans + dp(0, 0) << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Incorrect 5 ms 512 KB Output isn't correct
3 Incorrect 6 ms 512 KB Output isn't correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Incorrect 5 ms 512 KB Output isn't correct
15 Incorrect 5 ms 384 KB Output isn't correct
16 Incorrect 6 ms 512 KB Output isn't correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Incorrect 5 ms 512 KB Output isn't correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Incorrect 7 ms 512 KB Output isn't correct
30 Incorrect 6 ms 512 KB Output isn't correct
31 Correct 7 ms 512 KB Output is correct
32 Incorrect 7 ms 512 KB Output isn't correct
33 Correct 6 ms 512 KB Output is correct
34 Correct 7 ms 512 KB Output is correct
35 Correct 7 ms 512 KB Output is correct
36 Correct 7 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1664 KB Output is correct
2 Correct 39 ms 2176 KB Output is correct
3 Correct 26 ms 1272 KB Output is correct
4 Correct 28 ms 1664 KB Output is correct
5 Incorrect 40 ms 2168 KB Output isn't correct
6 Incorrect 37 ms 2432 KB Output isn't correct
7 Incorrect 30 ms 1784 KB Output isn't correct
8 Incorrect 33 ms 1916 KB Output isn't correct
9 Correct 39 ms 2176 KB Output is correct
10 Incorrect 35 ms 2040 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 490 ms 23548 KB Output isn't correct
2 Incorrect 347 ms 19960 KB Output isn't correct
3 Incorrect 471 ms 23800 KB Output isn't correct
4 Incorrect 361 ms 22392 KB Output isn't correct
5 Incorrect 571 ms 27360 KB Output isn't correct
6 Incorrect 359 ms 16844 KB Output isn't correct
7 Incorrect 562 ms 24952 KB Output isn't correct
8 Incorrect 617 ms 27128 KB Output isn't correct
9 Incorrect 452 ms 21136 KB Output isn't correct
10 Incorrect 471 ms 20728 KB Output isn't correct
11 Incorrect 357 ms 22384 KB Output isn't correct
12 Incorrect 573 ms 27640 KB Output isn't correct
13 Incorrect 530 ms 26492 KB Output isn't correct
14 Incorrect 405 ms 23160 KB Output isn't correct
15 Incorrect 625 ms 26744 KB Output isn't correct
16 Incorrect 316 ms 20984 KB Output isn't correct
17 Incorrect 495 ms 23544 KB Output isn't correct
18 Incorrect 470 ms 23672 KB Output isn't correct
19 Incorrect 347 ms 19960 KB Output isn't correct
20 Incorrect 533 ms 23140 KB Output isn't correct