Submission #561640

# Submission time Handle Problem Language Result Execution time Memory
561640 2022-05-13T10:00:54 Z fatemetmhr Copy and Paste 3 (JOI22_copypaste3) C++17
25 / 100
514 ms 146476 KB
// Be name khoda //

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb     push_back
#define all(x) x.begin(), x.end()
#define fi     first
#define se     second

const int maxn5 = 2e2 + 5;
const int maxnt = 8e5 + 10;
const ll  inf   = 1e15;

ll dp[maxn5][maxn5][maxn5], cost[maxn5][maxn5];
bool is_equa[maxn5][maxn5][maxn5];


int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n, a, b, c; string s;
    cin >> n >> s >> a >> b >> c;

    for(int len = 2; len <= n; len++) for(int l = 0; l + len - 1 < n; l++) for(int k = 1; k * 2 <= len; k++){
        int r = l + len - 1;
        if(k == 1)
            is_equa[l][r][k] = (s[l] == s[r]);
        else
            is_equa[l][r][k] = (s[l + k - 1] == s[r]) && is_equa[l][r - 1][k - 1];
    }

    //cout << is_equa[2][7][2] << ' ' << is_equa[2][7][3] << endl;

    for(int len = 1; len <= n; len++) for(int l = 0; l + len - 1 < n; l++){
        int r = l + len - 1;
        for(int k = 1; k <= len; k++){
            if(k == len){
                dp[l][r][k] = c;
                continue;
            }

            dp[l][r][k] = dp[l + 1][r][k] + a;
            if(k * 2 <= len && is_equa[l][r][k])
                dp[l][r][k] = min(dp[l][r][k], dp[l + k][r][k] + c);
        }
    }

    for(int i = 0; i < n; i++)
        cost[i][i] = a;

    for(int len = 2; len <= n; len++) for(int l = 0; l + len - 1 < n; l++){
        int r = l + len - 1;
        cost[l][r] = min(a + cost[l + 1][r], a + cost[l][r - 1]);
        //cout << "begin " << l << ' ' << r << ' '<< cost[l][r] << ' ' << a << ' ' << len << endl;
        for(int k = 1; k * 2 <= len; k++) if(is_equa[l][r][k]){
            cost[l][r] = min(cost[l][r], cost[l][l + k - 1] + b + c + dp[l + k][r][k]);
            //cout << l << ' '<< r << ' ' << k << ' ' << cost[l][r] << endl;
        }
    }

    cout << cost[0][n - 1] << endl;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Runtime error 514 ms 146476 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 712 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 1 ms 1360 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 1 ms 1400 KB Output is correct
25 Correct 1 ms 1364 KB Output is correct
26 Correct 1 ms 1408 KB Output is correct
27 Correct 1 ms 1364 KB Output is correct
28 Correct 1 ms 1364 KB Output is correct
29 Correct 1 ms 1352 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
31 Correct 1 ms 1364 KB Output is correct
32 Correct 1 ms 1364 KB Output is correct
33 Correct 1 ms 1364 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 584 KB Output is correct
39 Correct 1 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 712 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 1 ms 1360 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 1 ms 1400 KB Output is correct
25 Correct 1 ms 1364 KB Output is correct
26 Correct 1 ms 1408 KB Output is correct
27 Correct 1 ms 1364 KB Output is correct
28 Correct 1 ms 1364 KB Output is correct
29 Correct 1 ms 1352 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
31 Correct 1 ms 1364 KB Output is correct
32 Correct 1 ms 1364 KB Output is correct
33 Correct 1 ms 1364 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 584 KB Output is correct
39 Correct 1 ms 1364 KB Output is correct
40 Correct 4 ms 7580 KB Output is correct
41 Correct 29 ms 38348 KB Output is correct
42 Correct 24 ms 38304 KB Output is correct
43 Correct 25 ms 38244 KB Output is correct
44 Correct 23 ms 38356 KB Output is correct
45 Correct 21 ms 38220 KB Output is correct
46 Correct 20 ms 38228 KB Output is correct
47 Correct 21 ms 38356 KB Output is correct
48 Correct 22 ms 38268 KB Output is correct
49 Correct 20 ms 38276 KB Output is correct
50 Correct 20 ms 38356 KB Output is correct
51 Correct 22 ms 38256 KB Output is correct
52 Correct 23 ms 38344 KB Output is correct
53 Correct 23 ms 38336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 712 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 1 ms 1360 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 1 ms 1400 KB Output is correct
25 Correct 1 ms 1364 KB Output is correct
26 Correct 1 ms 1408 KB Output is correct
27 Correct 1 ms 1364 KB Output is correct
28 Correct 1 ms 1364 KB Output is correct
29 Correct 1 ms 1352 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
31 Correct 1 ms 1364 KB Output is correct
32 Correct 1 ms 1364 KB Output is correct
33 Correct 1 ms 1364 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 584 KB Output is correct
39 Correct 1 ms 1364 KB Output is correct
40 Correct 4 ms 7580 KB Output is correct
41 Correct 29 ms 38348 KB Output is correct
42 Correct 24 ms 38304 KB Output is correct
43 Correct 25 ms 38244 KB Output is correct
44 Correct 23 ms 38356 KB Output is correct
45 Correct 21 ms 38220 KB Output is correct
46 Correct 20 ms 38228 KB Output is correct
47 Correct 21 ms 38356 KB Output is correct
48 Correct 22 ms 38268 KB Output is correct
49 Correct 20 ms 38276 KB Output is correct
50 Correct 20 ms 38356 KB Output is correct
51 Correct 22 ms 38256 KB Output is correct
52 Correct 23 ms 38344 KB Output is correct
53 Correct 23 ms 38336 KB Output is correct
54 Runtime error 54 ms 32412 KB Execution killed with signal 11
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Runtime error 514 ms 146476 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -