답안 #242932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242932 2020-06-29T21:06:23 Z Bruteforceman Vim (BOI13_vim) C++11
42.5 / 100
40 ms 2296 KB
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
const int maxn = 5005; // 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 512 KB Output is correct
2 Incorrect 5 ms 512 KB Output isn't correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 8 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 432 KB Output is correct
11 Correct 5 ms 416 KB Output is correct
12 Correct 5 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 5 ms 512 KB Output isn't correct
17 Correct 8 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Incorrect 6 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
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1656 KB Output is correct
2 Correct 39 ms 2044 KB Output is correct
3 Correct 20 ms 1280 KB Output is correct
4 Correct 28 ms 1656 KB Output is correct
5 Incorrect 40 ms 2168 KB Output isn't correct
6 Incorrect 37 ms 2296 KB Output isn't correct
7 Incorrect 29 ms 1792 KB Output isn't correct
8 Incorrect 33 ms 1792 KB Output isn't correct
9 Correct 38 ms 2040 KB Output is correct
10 Incorrect 33 ms 2048 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 8 ms 792 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 8 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 9 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 9 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 9 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 9 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 8 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 8 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 8 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 8 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 8 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 8 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)