답안 #538744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
538744 2022-03-17T16:26:00 Z Lobo Vim (BOI13_vim) C++17
55 / 100
974 ms 296748 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef long long ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
 
#define maxn 5050
 
ii n, a[maxn], dp[maxn][maxn], mark[maxn][maxn], px[maxn][20], pse[maxn];
 
ii sol(ii i, ii j) {
    if(pse[n] - pse[j-1] == 0) return 0;
    if(i > n) return INFii;
    if(mark[i][j]) return dp[i][j];
 
    mark[i][j] = 1;
 
    if(a[j] != 'e'-'a') return dp[i][j] = sol(i,j+1);
 
    ii ans = INFii;
 
    for(ii c = 0; c <= 'j'-'a'; c++) {
        if(c == 'e'-'a') continue;
        if(px[i+1][c] != 0) ans = min(ans, sol(px[i+1][c],j)+2); //i+1 para nao contar com ele mesmo
    }
 
    if(j <= i) {
        ans = min(ans, sol(j+1,i+1) + (i-j) + (pse[i]-pse[j-1]));
    }
 
    return dp[i][j] = ans;
}
 
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
 
    // freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);
 
    string s;
    cin >> n >> s;
 
    for(ii i = 1; i <= n; i++) {
        pse[i] = pse[i-1];
        if(s[i-1] == 'e') {
            pse[i]++;
        }
 
        a[i] = s[i-1]-'a';
    }
 
    for(ii i = n; i >= 1; i--) {
        for(ii c = 0; c <= 'j'-'a'; c++) {
            px[i][c] = px[i+1][c];
        }
        px[i][a[i]] = i;
    }
 
    for(ii i = 1; i <= n; i++) {
        for(ii c = 0; c <= 'j'-'a'; c++) {
            //cout << i << " " << (char) (c+'a') << " == " << px[i][c] << endl;
        }
    }
 
    cout << sol(1,1) << endl;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4948 KB Output is correct
2 Correct 7 ms 4564 KB Output is correct
3 Correct 4 ms 4180 KB Output is correct
4 Correct 6 ms 3924 KB Output is correct
5 Correct 6 ms 3796 KB Output is correct
6 Correct 8 ms 4632 KB Output is correct
7 Correct 7 ms 5076 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 7 ms 4944 KB Output is correct
14 Correct 6 ms 4692 KB Output is correct
15 Correct 4 ms 4180 KB Output is correct
16 Correct 5 ms 4420 KB Output is correct
17 Correct 8 ms 5712 KB Output is correct
18 Correct 4 ms 3796 KB Output is correct
19 Correct 3 ms 2884 KB Output is correct
20 Correct 4 ms 3412 KB Output is correct
21 Correct 5 ms 3924 KB Output is correct
22 Correct 9 ms 3788 KB Output is correct
23 Correct 7 ms 6356 KB Output is correct
24 Correct 7 ms 5064 KB Output is correct
25 Correct 7 ms 5236 KB Output is correct
26 Correct 7 ms 5460 KB Output is correct
27 Correct 10 ms 4692 KB Output is correct
28 Correct 8 ms 4564 KB Output is correct
29 Correct 8 ms 5076 KB Output is correct
30 Correct 7 ms 5960 KB Output is correct
31 Correct 6 ms 5064 KB Output is correct
32 Correct 7 ms 5972 KB Output is correct
33 Correct 7 ms 5704 KB Output is correct
34 Correct 5 ms 4436 KB Output is correct
35 Correct 8 ms 3992 KB Output is correct
36 Correct 7 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 596 ms 196600 KB Output isn't correct
2 Correct 933 ms 227716 KB Output is correct
3 Incorrect 230 ms 82768 KB Output isn't correct
4 Incorrect 555 ms 196532 KB Output isn't correct
5 Correct 933 ms 232768 KB Output is correct
6 Correct 953 ms 296748 KB Output is correct
7 Incorrect 683 ms 227872 KB Output isn't correct
8 Incorrect 706 ms 226076 KB Output isn't correct
9 Correct 961 ms 227488 KB Output is correct
10 Correct 974 ms 238116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 792 KB Execution killed with signal 11
2 Runtime error 8 ms 852 KB Execution killed with signal 11
3 Runtime error 7 ms 852 KB Execution killed with signal 11
4 Runtime error 8 ms 1108 KB Execution killed with signal 11
5 Runtime error 7 ms 988 KB Execution killed with signal 11
6 Runtime error 7 ms 796 KB Execution killed with signal 11
7 Runtime error 11 ms 852 KB Execution killed with signal 11
8 Runtime error 10 ms 792 KB Execution killed with signal 11
9 Runtime error 9 ms 852 KB Execution killed with signal 11
10 Runtime error 10 ms 796 KB Execution killed with signal 11
11 Runtime error 10 ms 1000 KB Execution killed with signal 11
12 Runtime error 8 ms 980 KB Execution killed with signal 11
13 Runtime error 7 ms 980 KB Execution killed with signal 11
14 Runtime error 7 ms 980 KB Execution killed with signal 11
15 Runtime error 7 ms 980 KB Execution killed with signal 11
16 Runtime error 7 ms 852 KB Execution killed with signal 11
17 Runtime error 7 ms 852 KB Execution killed with signal 11
18 Runtime error 6 ms 852 KB Execution killed with signal 11
19 Runtime error 7 ms 852 KB Execution killed with signal 11
20 Runtime error 7 ms 852 KB Execution killed with signal 11