# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
41064 |
2018-02-12T09:59:49 Z |
livace |
Vim (BOI13_vim) |
C++14 |
|
41 ms |
10252 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;
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 (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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
1 ms |
484 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
484 KB |
Output isn't correct |
4 |
Correct |
2 ms |
612 KB |
Output is correct |
5 |
Correct |
1 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
616 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
640 KB |
Output is correct |
9 |
Correct |
1 ms |
644 KB |
Output is correct |
10 |
Correct |
1 ms |
648 KB |
Output is correct |
11 |
Correct |
1 ms |
752 KB |
Output is correct |
12 |
Correct |
1 ms |
752 KB |
Output is correct |
13 |
Correct |
2 ms |
752 KB |
Output is correct |
14 |
Incorrect |
1 ms |
768 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
776 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
780 KB |
Output isn't correct |
17 |
Correct |
2 ms |
784 KB |
Output is correct |
18 |
Correct |
1 ms |
788 KB |
Output is correct |
19 |
Incorrect |
2 ms |
856 KB |
Output isn't correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
2 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
2 ms |
856 KB |
Output is correct |
27 |
Correct |
2 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Incorrect |
2 ms |
856 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
856 KB |
Output isn't correct |
31 |
Correct |
2 ms |
856 KB |
Output is correct |
32 |
Incorrect |
2 ms |
856 KB |
Output isn't correct |
33 |
Correct |
2 ms |
856 KB |
Output is correct |
34 |
Correct |
2 ms |
856 KB |
Output is correct |
35 |
Correct |
2 ms |
856 KB |
Output is correct |
36 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1376 KB |
Output isn't correct |
2 |
Correct |
4 ms |
1512 KB |
Output is correct |
3 |
Incorrect |
3 ms |
1512 KB |
Output isn't correct |
4 |
Incorrect |
5 ms |
1512 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
1512 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
1512 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
1512 KB |
Output isn't correct |
8 |
Incorrect |
5 ms |
1512 KB |
Output isn't correct |
9 |
Correct |
5 ms |
1512 KB |
Output is correct |
10 |
Incorrect |
4 ms |
1512 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
8172 KB |
Output isn't correct |
2 |
Incorrect |
38 ms |
8172 KB |
Output isn't correct |
3 |
Incorrect |
28 ms |
8452 KB |
Output isn't correct |
4 |
Incorrect |
27 ms |
9660 KB |
Output isn't correct |
5 |
Incorrect |
32 ms |
9660 KB |
Output isn't correct |
6 |
Incorrect |
37 ms |
9660 KB |
Output isn't correct |
7 |
Incorrect |
29 ms |
9660 KB |
Output isn't correct |
8 |
Incorrect |
27 ms |
9660 KB |
Output isn't correct |
9 |
Incorrect |
30 ms |
9660 KB |
Output isn't correct |
10 |
Incorrect |
34 ms |
9660 KB |
Output isn't correct |
11 |
Incorrect |
26 ms |
10160 KB |
Output isn't correct |
12 |
Incorrect |
33 ms |
10252 KB |
Output isn't correct |
13 |
Incorrect |
30 ms |
10252 KB |
Output isn't correct |
14 |
Incorrect |
32 ms |
10252 KB |
Output isn't correct |
15 |
Incorrect |
41 ms |
10252 KB |
Output isn't correct |
16 |
Incorrect |
19 ms |
10252 KB |
Output isn't correct |
17 |
Incorrect |
28 ms |
10252 KB |
Output isn't correct |
18 |
Incorrect |
26 ms |
10252 KB |
Output isn't correct |
19 |
Incorrect |
26 ms |
10252 KB |
Output isn't correct |
20 |
Incorrect |
33 ms |
10252 KB |
Output isn't correct |