답안 #531074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531074 2022-02-27T16:23:15 Z Lobo Vim (BOI13_vim) C++17
55 / 100
559 ms 154012 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 int 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(j == n+1) 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 4 ms 3780 KB Output is correct
2 Correct 4 ms 3520 KB Output is correct
3 Correct 3 ms 3400 KB Output is correct
4 Correct 3 ms 3140 KB Output is correct
5 Correct 3 ms 3024 KB Output is correct
6 Correct 5 ms 3536 KB Output is correct
7 Correct 6 ms 3792 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 4 ms 3792 KB Output is correct
14 Correct 4 ms 3536 KB Output is correct
15 Correct 3 ms 3408 KB Output is correct
16 Correct 3 ms 3408 KB Output is correct
17 Correct 5 ms 4304 KB Output is correct
18 Correct 4 ms 3024 KB Output is correct
19 Correct 2 ms 2372 KB Output is correct
20 Correct 3 ms 2640 KB Output is correct
21 Correct 3 ms 3152 KB Output is correct
22 Correct 3 ms 3024 KB Output is correct
23 Correct 6 ms 4944 KB Output is correct
24 Correct 4 ms 4036 KB Output is correct
25 Correct 5 ms 4048 KB Output is correct
26 Correct 6 ms 4176 KB Output is correct
27 Correct 7 ms 3640 KB Output is correct
28 Correct 5 ms 3472 KB Output is correct
29 Correct 4 ms 3792 KB Output is correct
30 Correct 4 ms 4432 KB Output is correct
31 Correct 4 ms 3920 KB Output is correct
32 Correct 5 ms 4560 KB Output is correct
33 Correct 5 ms 4432 KB Output is correct
34 Correct 5 ms 3408 KB Output is correct
35 Correct 4 ms 3024 KB Output is correct
36 Correct 5 ms 3792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 323 ms 106220 KB Output isn't correct
2 Correct 519 ms 123304 KB Output is correct
3 Incorrect 129 ms 48460 KB Output isn't correct
4 Incorrect 317 ms 106216 KB Output isn't correct
5 Correct 559 ms 125284 KB Output is correct
6 Correct 480 ms 154012 KB Output is correct
7 Incorrect 423 ms 121440 KB Output isn't correct
8 Incorrect 381 ms 120280 KB Output isn't correct
9 Correct 539 ms 123280 KB Output is correct
10 Correct 543 ms 128044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 848 KB Execution killed with signal 11
2 Runtime error 5 ms 780 KB Execution killed with signal 11
3 Runtime error 4 ms 780 KB Execution killed with signal 11
4 Runtime error 4 ms 972 KB Execution killed with signal 11
5 Runtime error 4 ms 976 KB Execution killed with signal 11
6 Runtime error 6 ms 848 KB Execution killed with signal 11
7 Runtime error 4 ms 848 KB Execution killed with signal 11
8 Runtime error 7 ms 788 KB Execution killed with signal 11
9 Runtime error 4 ms 784 KB Execution killed with signal 11
10 Runtime error 6 ms 848 KB Execution killed with signal 11
11 Runtime error 4 ms 976 KB Execution killed with signal 11
12 Runtime error 5 ms 916 KB Execution killed with signal 11
13 Runtime error 4 ms 976 KB Execution killed with signal 11
14 Runtime error 5 ms 968 KB Execution killed with signal 11
15 Runtime error 4 ms 964 KB Execution killed with signal 11
16 Runtime error 4 ms 848 KB Execution killed with signal 11
17 Runtime error 4 ms 848 KB Execution killed with signal 11
18 Runtime error 4 ms 848 KB Execution killed with signal 11
19 Runtime error 4 ms 848 KB Execution killed with signal 11
20 Runtime error 5 ms 848 KB Execution killed with signal 11