답안 #242931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242931 2020-06-29T21:03:42 Z Bruteforceman Vim (BOI13_vim) C++11
42.5 / 100
65 ms 98680 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];
int mem[maxn][maxn];
int cnt[maxn];

int dp(int now, int done) {
  int jump = opt[done];
  if(jump == n) return 0;
  int &ans = mem[now][done];
  if(ans != -1) return ans;
  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 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');
  memset(mem, -1, sizeof mem);
  cout << ans + dp(0, 0) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 98424 KB Output is correct
2 Incorrect 57 ms 98456 KB Output isn't correct
3 Incorrect 50 ms 98424 KB Output isn't correct
4 Correct 52 ms 98424 KB Output is correct
5 Correct 56 ms 98424 KB Output is correct
6 Correct 59 ms 98424 KB Output is correct
7 Correct 52 ms 98424 KB Output is correct
8 Correct 50 ms 98424 KB Output is correct
9 Correct 59 ms 98424 KB Output is correct
10 Correct 50 ms 98408 KB Output is correct
11 Correct 52 ms 98424 KB Output is correct
12 Correct 51 ms 98424 KB Output is correct
13 Correct 51 ms 98424 KB Output is correct
14 Incorrect 57 ms 98424 KB Output isn't correct
15 Incorrect 55 ms 98424 KB Output isn't correct
16 Incorrect 56 ms 98424 KB Output isn't correct
17 Correct 56 ms 98424 KB Output is correct
18 Correct 56 ms 98424 KB Output is correct
19 Incorrect 51 ms 98424 KB Output isn't correct
20 Correct 51 ms 98424 KB Output is correct
21 Correct 57 ms 98428 KB Output is correct
22 Correct 57 ms 98428 KB Output is correct
23 Correct 52 ms 98424 KB Output is correct
24 Correct 50 ms 98424 KB Output is correct
25 Correct 51 ms 98424 KB Output is correct
26 Correct 51 ms 98424 KB Output is correct
27 Correct 57 ms 98424 KB Output is correct
28 Correct 50 ms 98424 KB Output is correct
29 Incorrect 52 ms 98424 KB Output isn't correct
30 Incorrect 50 ms 98424 KB Output isn't correct
31 Correct 51 ms 98424 KB Output is correct
32 Incorrect 57 ms 98424 KB Output isn't correct
33 Correct 52 ms 98424 KB Output is correct
34 Correct 51 ms 98424 KB Output is correct
35 Correct 52 ms 98424 KB Output is correct
36 Correct 50 ms 98460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 98680 KB Output is correct
2 Correct 53 ms 98680 KB Output is correct
3 Correct 65 ms 98552 KB Output is correct
4 Correct 60 ms 98680 KB Output is correct
5 Incorrect 61 ms 98680 KB Output isn't correct
6 Incorrect 54 ms 98680 KB Output isn't correct
7 Incorrect 62 ms 98680 KB Output isn't correct
8 Incorrect 55 ms 98560 KB Output isn't correct
9 Correct 57 ms 98680 KB Output is correct
10 Incorrect 55 ms 98680 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 12 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 14 ms 832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 12 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 12 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 12 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 13 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 12 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 12 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 13 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 13 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 13 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 12 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 12 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 12 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 12 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 13 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 12 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 12 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 13 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)