답안 #41065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41065 2018-02-12T10:04:16 Z livace Vim (BOI13_vim) C++14
39.5 / 100
44 ms 8940 KB
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,unroll-all-loops")
// #pragma GCC option("arch=native","tune=native")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>
using namespace std;

#define f(_i, _n) for (auto _i = 0; _i < _n; _i++)
#define F(_i, _k, _n) for (auto _i = _k; _i < _n; _i++)
#define re return
#define pb push_back
#define all(_v) _v.begin(), _v.end()
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define fi first
#define se second

typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;

int nxt[100500][15];
int dp[100500][15];

int cnt_e;

int tmp_nxt[10];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  n = (int)s.size();
  f(i, n) {
    s[i] -= 'a';
    if (s[i] == 4) {
      cnt_e++;
    }
  }
  f(i, 10) {
    tmp_nxt[i] = -1;
  }
  for (int i = n - 1; i >= 0; i--) {
    f(j, 10) {
      nxt[i][j] = tmp_nxt[j];
    }
    tmp_nxt[(int)s[i]] = i;
  }
  f(i, n + 1) {
    f(j, 11) {
      if (j == 4) {
        continue;
      }
      dp[i][j] = 1e9;
    }
  }
  dp[0][10] = 0;
  int ans = 1e9;
  f(i, n) {
    f(j, 11) {
      if (j == 4) {
        continue;
      }
      // cerr << i << ' ' << j << ' ' << dp[i][j] << '\n';
      int nxt_e;
      if (j == 10) {
        nxt_e = nxt[i][4];
      } else {
        nxt_e = nxt[nxt[i][j]][4];
      }
      if (nxt_e == -1) {
        ans = min(ans, dp[i][j]);
        continue;
      }
      f(k, 10) {
        if (k == 4) {
          continue;
        }
        int pos = nxt[i][k];
        if (pos == -1) {
          continue;
        }
        if (nxt_e > pos) {
          dp[pos][10] = min(dp[pos][10], dp[i][j] + 2);
        } else {
          if (pos == nxt_e + 1) {
            dp[nxt_e + 1][10] = min(dp[nxt_e + 1][10], dp[i][j] + 2 + pos - nxt_e);
          } else {
            dp[nxt_e + 1][k] = min(dp[nxt_e + 1][k], dp[i][j] + 2 + pos - nxt_e);
          }
        }
      }
    }
  }
  cout << ans + cnt_e;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 480 KB Output isn't correct
3 Incorrect 2 ms 480 KB Output isn't correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 1 ms 624 KB Output is correct
9 Correct 1 ms 624 KB Output is correct
10 Correct 1 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 2 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Incorrect 2 ms 668 KB Output isn't correct
15 Incorrect 2 ms 668 KB Output isn't correct
16 Incorrect 1 ms 668 KB Output isn't correct
17 Correct 2 ms 668 KB Output is correct
18 Correct 1 ms 668 KB Output is correct
19 Incorrect 1 ms 688 KB Output isn't correct
20 Correct 2 ms 688 KB Output is correct
21 Correct 2 ms 688 KB Output is correct
22 Correct 2 ms 688 KB Output is correct
23 Correct 2 ms 688 KB Output is correct
24 Correct 2 ms 688 KB Output is correct
25 Correct 2 ms 688 KB Output is correct
26 Correct 2 ms 688 KB Output is correct
27 Correct 2 ms 688 KB Output is correct
28 Correct 2 ms 688 KB Output is correct
29 Incorrect 2 ms 688 KB Output isn't correct
30 Incorrect 2 ms 688 KB Output isn't correct
31 Correct 2 ms 688 KB Output is correct
32 Incorrect 2 ms 688 KB Output isn't correct
33 Correct 2 ms 688 KB Output is correct
34 Correct 2 ms 688 KB Output is correct
35 Correct 2 ms 688 KB Output is correct
36 Correct 2 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1132 KB Output isn't correct
2 Correct 4 ms 1132 KB Output is correct
3 Incorrect 3 ms 1132 KB Output isn't correct
4 Incorrect 4 ms 1160 KB Output isn't correct
5 Incorrect 4 ms 1160 KB Output isn't correct
6 Incorrect 5 ms 1160 KB Output isn't correct
7 Incorrect 4 ms 1160 KB Output isn't correct
8 Incorrect 4 ms 1260 KB Output isn't correct
9 Correct 4 ms 1260 KB Output is correct
10 Incorrect 4 ms 1260 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 7788 KB Output isn't correct
2 Incorrect 31 ms 7788 KB Output isn't correct
3 Incorrect 31 ms 7788 KB Output isn't correct
4 Incorrect 29 ms 8940 KB Output isn't correct
5 Incorrect 34 ms 8940 KB Output isn't correct
6 Incorrect 32 ms 8940 KB Output isn't correct
7 Incorrect 36 ms 8940 KB Output isn't correct
8 Incorrect 30 ms 8940 KB Output isn't correct
9 Incorrect 33 ms 8940 KB Output isn't correct
10 Incorrect 36 ms 8940 KB Output isn't correct
11 Incorrect 29 ms 8940 KB Output isn't correct
12 Incorrect 35 ms 8940 KB Output isn't correct
13 Incorrect 35 ms 8940 KB Output isn't correct
14 Incorrect 34 ms 8940 KB Output isn't correct
15 Incorrect 44 ms 8940 KB Output isn't correct
16 Incorrect 22 ms 8940 KB Output isn't correct
17 Incorrect 32 ms 8940 KB Output isn't correct
18 Incorrect 31 ms 8940 KB Output isn't correct
19 Incorrect 30 ms 8940 KB Output isn't correct
20 Incorrect 38 ms 8940 KB Output isn't correct