Submission #552057

# Submission time Handle Problem Language Result Execution time Memory
552057 2022-04-22T10:52:33 Z Ronin13 Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
766 ms 70736 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;

const int NMAX = 2501;
const ll inf = 1e9 + 1;


int dp1[NMAX][NMAX];
int adj[NMAX][NMAX];
ll dp[NMAX][NMAX];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    ll a, b, c; cin >> a >> b >> c;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j < i; j++){
            if(s[i - 1] != s[j - 1]) dp1[i][j] = 0;
            else dp1[i][j] = dp1[i - 1][j - 1] + 1;
        }
    }
    /*for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cout << dp1[i][j] << ' ';
        }
        cout << "\n";
    }*/
    for(int i = 1; i <= n; i++){
        int mn = 0;
        for(int j = i - 1; j > 0; j--){
            int x = min(dp1[i][j], i - j);
            while(mn < x){
                mn++;
                adj[i - mn + 1][mn] = j - mn + 1;
            }
        }
    }
    vector <vector <int> > vec(n + 1);
    for(int i = 1; i <= n; i++){
        for(int i = 1; i <= n; i++) vec[i].clear();
        for(int j = i; j >= 1; j--){
            int cur = j;
            int len = i - j + 1;
            while(cur){
                vec[cur].pb(len);
                cur = adj[cur][len];
            }
        }
        ll cnt[n + 1];
        for(int i = 1; i <= n; i++){
          cnt[i] = 0;
        }
        ll mn = 0;
        dp[i][i] = a;
        for(int j = i; j > 0; j--){
            dp[i][j] = dp[i - 1][j] + a;
            for(int to : vec[j]){
                cnt[to]++;
                mn = min(mn, (c - to * a) * cnt[to] + dp[i][i - to + 1] + b);
            }
            dp[i][j] = min(dp[i][j], mn + (i - j + 1) * a);
        }
    }
    /*for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cout << dp[i][j] << ' ';
        }
        cout << "\n";
    }*/
    cout << dp[n][1];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 325 ms 45328 KB Output is correct
4 Correct 440 ms 50760 KB Output is correct
5 Correct 460 ms 56836 KB Output is correct
6 Correct 576 ms 63412 KB Output is correct
7 Correct 699 ms 70696 KB Output is correct
8 Correct 766 ms 70636 KB Output is correct
9 Correct 663 ms 70736 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 0 ms 596 KB Output is correct
33 Correct 0 ms 596 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 0 ms 596 KB Output is correct
33 Correct 0 ms 596 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 1364 KB Output is correct
41 Correct 3 ms 3028 KB Output is correct
42 Correct 2 ms 2900 KB Output is correct
43 Correct 2 ms 2900 KB Output is correct
44 Correct 3 ms 2900 KB Output is correct
45 Correct 3 ms 2900 KB Output is correct
46 Correct 3 ms 2772 KB Output is correct
47 Correct 3 ms 2960 KB Output is correct
48 Correct 2 ms 2900 KB Output is correct
49 Correct 2 ms 2900 KB Output is correct
50 Correct 3 ms 2900 KB Output is correct
51 Correct 3 ms 2900 KB Output is correct
52 Correct 3 ms 2948 KB Output is correct
53 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 0 ms 596 KB Output is correct
33 Correct 0 ms 596 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 1364 KB Output is correct
41 Correct 3 ms 3028 KB Output is correct
42 Correct 2 ms 2900 KB Output is correct
43 Correct 2 ms 2900 KB Output is correct
44 Correct 3 ms 2900 KB Output is correct
45 Correct 3 ms 2900 KB Output is correct
46 Correct 3 ms 2772 KB Output is correct
47 Correct 3 ms 2960 KB Output is correct
48 Correct 2 ms 2900 KB Output is correct
49 Correct 2 ms 2900 KB Output is correct
50 Correct 3 ms 2900 KB Output is correct
51 Correct 3 ms 2900 KB Output is correct
52 Correct 3 ms 2948 KB Output is correct
53 Correct 2 ms 2772 KB Output is correct
54 Correct 7 ms 6808 KB Output is correct
55 Correct 78 ms 19380 KB Output is correct
56 Correct 27 ms 18216 KB Output is correct
57 Correct 24 ms 18260 KB Output is correct
58 Correct 21 ms 18260 KB Output is correct
59 Correct 20 ms 18164 KB Output is correct
60 Correct 20 ms 18180 KB Output is correct
61 Correct 27 ms 18952 KB Output is correct
62 Correct 74 ms 19240 KB Output is correct
63 Correct 22 ms 18704 KB Output is correct
64 Correct 24 ms 18616 KB Output is correct
65 Correct 47 ms 19136 KB Output is correct
66 Correct 45 ms 19092 KB Output is correct
67 Correct 18 ms 18132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 325 ms 45328 KB Output is correct
14 Correct 440 ms 50760 KB Output is correct
15 Correct 460 ms 56836 KB Output is correct
16 Correct 576 ms 63412 KB Output is correct
17 Correct 699 ms 70696 KB Output is correct
18 Correct 766 ms 70636 KB Output is correct
19 Correct 663 ms 70736 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 0 ms 596 KB Output is correct
50 Correct 0 ms 596 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 1 ms 1364 KB Output is correct
58 Correct 3 ms 3028 KB Output is correct
59 Correct 2 ms 2900 KB Output is correct
60 Correct 2 ms 2900 KB Output is correct
61 Correct 3 ms 2900 KB Output is correct
62 Correct 3 ms 2900 KB Output is correct
63 Correct 3 ms 2772 KB Output is correct
64 Correct 3 ms 2960 KB Output is correct
65 Correct 2 ms 2900 KB Output is correct
66 Correct 2 ms 2900 KB Output is correct
67 Correct 3 ms 2900 KB Output is correct
68 Correct 3 ms 2900 KB Output is correct
69 Correct 3 ms 2948 KB Output is correct
70 Correct 2 ms 2772 KB Output is correct
71 Correct 7 ms 6808 KB Output is correct
72 Correct 78 ms 19380 KB Output is correct
73 Correct 27 ms 18216 KB Output is correct
74 Correct 24 ms 18260 KB Output is correct
75 Correct 21 ms 18260 KB Output is correct
76 Correct 20 ms 18164 KB Output is correct
77 Correct 20 ms 18180 KB Output is correct
78 Correct 27 ms 18952 KB Output is correct
79 Correct 74 ms 19240 KB Output is correct
80 Correct 22 ms 18704 KB Output is correct
81 Correct 24 ms 18616 KB Output is correct
82 Correct 47 ms 19136 KB Output is correct
83 Correct 45 ms 19092 KB Output is correct
84 Correct 18 ms 18132 KB Output is correct
85 Correct 75 ms 34056 KB Output is correct
86 Correct 215 ms 64212 KB Output is correct
87 Correct 151 ms 64200 KB Output is correct
88 Correct 119 ms 64160 KB Output is correct
89 Correct 127 ms 64104 KB Output is correct
90 Correct 108 ms 64108 KB Output is correct
91 Correct 359 ms 70208 KB Output is correct
92 Correct 533 ms 70368 KB Output is correct
93 Correct 147 ms 67828 KB Output is correct
94 Correct 186 ms 67144 KB Output is correct
95 Correct 422 ms 69584 KB Output is correct
96 Correct 438 ms 69488 KB Output is correct
97 Correct 102 ms 64068 KB Output is correct