Submission #552056

# Submission time Handle Problem Language Result Execution time Memory
552056 2022-04-22T10:51:52 Z Ronin13 Copy and Paste 3 (JOI22_copypaste3) C++14
57 / 100
331 ms 48348 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 = 2001;
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 1 ms 340 KB Output is correct
2 Correct 1 ms 324 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 274 ms 43736 KB Output is correct
4 Correct 331 ms 48348 KB Output is correct
5 Runtime error 27 ms 28376 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 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 328 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 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 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 324 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 468 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 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 328 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 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 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 324 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 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 2 ms 2900 KB Output is correct
46 Correct 2 ms 2772 KB Output is correct
47 Correct 2 ms 2900 KB Output is correct
48 Correct 2 ms 2900 KB Output is correct
49 Correct 2 ms 2900 KB Output is correct
50 Correct 2 ms 2900 KB Output is correct
51 Correct 3 ms 2900 KB Output is correct
52 Correct 2 ms 2900 KB Output is correct
53 Correct 2 ms 2868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 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 328 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 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 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 324 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 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 2 ms 2900 KB Output is correct
46 Correct 2 ms 2772 KB Output is correct
47 Correct 2 ms 2900 KB Output is correct
48 Correct 2 ms 2900 KB Output is correct
49 Correct 2 ms 2900 KB Output is correct
50 Correct 2 ms 2900 KB Output is correct
51 Correct 3 ms 2900 KB Output is correct
52 Correct 2 ms 2900 KB Output is correct
53 Correct 2 ms 2868 KB Output is correct
54 Correct 6 ms 6860 KB Output is correct
55 Correct 72 ms 19240 KB Output is correct
56 Correct 28 ms 18208 KB Output is correct
57 Correct 23 ms 18232 KB Output is correct
58 Correct 21 ms 18236 KB Output is correct
59 Correct 18 ms 18132 KB Output is correct
60 Correct 21 ms 18184 KB Output is correct
61 Correct 28 ms 18900 KB Output is correct
62 Correct 64 ms 19248 KB Output is correct
63 Correct 22 ms 18644 KB Output is correct
64 Correct 25 ms 18636 KB Output is correct
65 Correct 44 ms 19104 KB Output is correct
66 Correct 44 ms 19012 KB Output is correct
67 Correct 17 ms 18176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 274 ms 43736 KB Output is correct
14 Correct 331 ms 48348 KB Output is correct
15 Runtime error 27 ms 28376 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -