// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 5010, mod = 1e9 + 7, inf = 1e9 + 10;
//int DP[maxn][maxn];
int nxt[maxn][10], lst[10];
map<pii, int> dp;
vector<int> poses;
int solve(int i, int j){
if(i >= sz(poses))
return 0;
if(dp.count({i, j}))
return dp[{i, j}];
if(j >= poses[i])
return dp[{i, j}] = j - poses[i] + solve( upper_bound(poses.begin(), poses.end(), j) - poses.begin(), poses[i] );
int pt = lower_bound(nxt[j], nxt[j] + 10, poses[i]) - nxt[j];
/*
if(pt == 9)
return dp[{i, j}] = 2 + solve(i, nxt[j][8]);
int ans = 2 + solve(i, nxt[j][pt]);
if(pt != 0 && nxt[j][pt-1] != j)
ans = min(ans, 2 + solve(i, nxt[j][pt-1]) );
return dp[{i, j}] = ans;*/
int ans = inf;
for(int w = min(8, pt + 1) ; w >= 0 && nxt[j][w] != j && w >= pt-1; w--){
ans = min(ans, 2 + solve(i, nxt[j][w]));
}
return dp[{i, j}] = ans;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int n;
cin >> n;
string _s, s;
cin >> _s;
int ans = 0;
for(int i = 0; i < n; i++){
if(_s[i] == 'e')
ans+= 2;
if(_s[i] == 'e' && _s[i + 1] != 'e')
poses.PB(sz(s));
if(_s[i] != 'e')
s+= _s[i];
}
memset(lst, -1, sizeof lst);
memset(nxt, -1, sizeof nxt);
n = sz(s);
for(int i = n-1; i >= 0; i--){
for(int j = 0; j < 9; j++)
nxt[i][j] = (lst[j] == -1 ? i : lst[j]);
sort(nxt[i], nxt[i] + 9);
nxt[i][9] = inf;
int id = (s[i] - 'a') - (s[i] > 'e');
lst[id] = i;
}
/*
for(int i = sz(poses)-1; i >= 0; i--){
int pt = sz(poses)-1;
for(int j = n-1; j >= 0; j--){
DP[i][j] = inf;
if(pt >= i)
DP[i][j] = j - poses[i] + DP[pt + 1][poses[i]];
for(int k = 0; k < 9; k++)
if(nxt[j][k] != -1)
DP[i][j] = min(DP[i][j], 2 + DP[i][nxt[j][k]]);
if(poses[pt] == j)
pt--;
if(DP[i][j] != solve(i, j))
cout << "HHH " << " " << s[j-1] << s[j] << s[j+1] << " " << i << " " << j << " " << solve(i, j) << " " << DP[i][j] << endl;
}
}
*/
ans+= solve(0, 0);
return cout << ans << "\n", 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
8 |
Correct |
0 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
512 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Correct |
0 ms |
512 KB |
Output is correct |
13 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
23 |
Correct |
1 ms |
640 KB |
Output is correct |
24 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Incorrect |
1 ms |
528 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
33 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
34 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
35 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
36 |
Incorrect |
1 ms |
640 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1152 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
1408 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
896 KB |
Output isn't correct |
4 |
Incorrect |
5 ms |
1152 KB |
Output isn't correct |
5 |
Incorrect |
6 ms |
1408 KB |
Output isn't correct |
6 |
Incorrect |
5 ms |
1152 KB |
Output isn't correct |
7 |
Incorrect |
4 ms |
1152 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
1152 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
1408 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
1408 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
1408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
2 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
3 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
3 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
3 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
3 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
3 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
3 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
3 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
2 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
3 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
3 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
3 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Runtime error |
2 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Runtime error |
3 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
2 ms |
1408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
2 ms |
1408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Runtime error |
3 ms |
1408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Runtime error |
2 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Runtime error |
2 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |