Submission #548908

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

const int NMAX = 2501 + 1;
const int inf = 1e9 + 1;
const ll linf = 1e18 + 1;
const ll mod = 1e9 + 7;
const ll pr = 29;

ll po[NMAX];
ll h[NMAX];

void hashing(string &s){
    h[0] = 0;
    int n = s.size();
    for(int i = 1; i <= n; i++){
        ll x = s[i - 1] - 'a' + 1;
        h[i] = h[i - 1] * pr + x;
        h[i] %= mod;
    }
}

ll get(int l, int r){
    ll x = h[r] - h[l - 1] * po[r - l + 1];
    x %= mod;
    x += mod;
    x %= mod;
    return x;
}

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

int main(){
    po[0] = 1;
    for(int i = 1; i < NMAX; i++){
        po[i] = po[i - 1] * pr;
        po[i] %= mod;
    }
    for(int i = 1; i < NMAX; i++){
        for(int j = 1; j < NMAX; j++){
            dp[i][j] = linf;
        }
    }
    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;
    hashing(s);
    map <ll, int> mp;
    vector < vector <ll> > vec(n + 1);
    for(int i = 1; i <= n; i++){
        for(ll to : vec[i - 1]) mp[to] = i - 1;
        for(int j = i; j <= n; j++){
            ll x = get(i, j);
            int v = mp[x];
            if(v != 0)
            adj[i][j - i + 1] = v - (j - i);
            vec[j].pb(x);
        }
    }
    /*for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cout << adj[i][j] << ' ';
        }
        cout << "\n";
    }*/
    for(int r = 1; r <= n; r++){
        vector < vector <int> > v(n + 1);
        vector <ll> cnt(n + 1, 0);
        for(int i = 1; i <= r; i++){
            int cur = r - i + 1;
            while(cur){
                v[cur].pb(i);
                cur = adj[cur][i];
            }
        }
        ll mn = 0;
        dp[r][r] = a;
        for(int l = r; l >= 1; l--){
            for(ll to : v[l]){
                cnt[to]++;
                ll val = dp[r - to + 1][r] + b;
                val += (c - to * a) * cnt[to];
                mn = min(mn, val);
            }
            dp[l][r] = mn + (r - l + 1) * a;
            dp[l][r] = min(dp[l][r], dp[l][r - 1] + a);
        }
    }
    /*for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(dp[i][j] == linf) cout << "-1 ";
            else cout << dp[i][j] << " ";
        }
        cout << "\n";
    }*/
    cout << dp[1][n];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 49236 KB Output is correct
2 Correct 24 ms 49216 KB Output is correct
3 Correct 22 ms 49336 KB Output is correct
4 Correct 22 ms 49236 KB Output is correct
5 Correct 21 ms 49236 KB Output is correct
6 Correct 21 ms 49236 KB Output is correct
7 Correct 21 ms 49236 KB Output is correct
8 Correct 21 ms 49236 KB Output is correct
9 Correct 28 ms 49240 KB Output is correct
10 Correct 26 ms 49228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 49364 KB Output is correct
2 Correct 20 ms 49440 KB Output is correct
3 Correct 883 ms 78168 KB Output is correct
4 Correct 1128 ms 81752 KB Output is correct
5 Correct 1301 ms 86752 KB Output is correct
6 Correct 1602 ms 92684 KB Output is correct
7 Correct 1839 ms 99704 KB Output is correct
8 Correct 1870 ms 99804 KB Output is correct
9 Correct 1904 ms 99636 KB Output is correct
10 Correct 25 ms 49236 KB Output is correct
11 Correct 24 ms 49312 KB Output is correct
12 Correct 21 ms 49236 KB Output is correct
13 Correct 21 ms 49332 KB Output is correct
14 Correct 22 ms 49292 KB Output is correct
15 Correct 20 ms 49364 KB Output is correct
16 Correct 25 ms 49380 KB Output is correct
17 Correct 20 ms 49248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 49236 KB Output is correct
2 Correct 24 ms 49216 KB Output is correct
3 Correct 22 ms 49336 KB Output is correct
4 Correct 22 ms 49236 KB Output is correct
5 Correct 21 ms 49236 KB Output is correct
6 Correct 21 ms 49236 KB Output is correct
7 Correct 21 ms 49236 KB Output is correct
8 Correct 21 ms 49236 KB Output is correct
9 Correct 28 ms 49240 KB Output is correct
10 Correct 26 ms 49228 KB Output is correct
11 Correct 20 ms 49244 KB Output is correct
12 Correct 20 ms 49344 KB Output is correct
13 Correct 22 ms 49364 KB Output is correct
14 Correct 27 ms 49244 KB Output is correct
15 Correct 21 ms 49364 KB Output is correct
16 Correct 22 ms 49356 KB Output is correct
17 Correct 22 ms 49244 KB Output is correct
18 Correct 22 ms 49236 KB Output is correct
19 Correct 20 ms 49252 KB Output is correct
20 Correct 20 ms 49236 KB Output is correct
21 Correct 21 ms 49364 KB Output is correct
22 Correct 21 ms 49424 KB Output is correct
23 Correct 20 ms 49364 KB Output is correct
24 Correct 22 ms 49388 KB Output is correct
25 Correct 22 ms 49372 KB Output is correct
26 Correct 22 ms 49364 KB Output is correct
27 Correct 25 ms 49364 KB Output is correct
28 Correct 23 ms 49368 KB Output is correct
29 Correct 21 ms 49364 KB Output is correct
30 Correct 20 ms 49392 KB Output is correct
31 Correct 20 ms 49416 KB Output is correct
32 Correct 23 ms 49384 KB Output is correct
33 Correct 21 ms 49328 KB Output is correct
34 Correct 22 ms 49272 KB Output is correct
35 Correct 21 ms 49328 KB Output is correct
36 Correct 20 ms 49216 KB Output is correct
37 Correct 22 ms 49264 KB Output is correct
38 Correct 29 ms 49244 KB Output is correct
39 Correct 23 ms 49376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 49236 KB Output is correct
2 Correct 24 ms 49216 KB Output is correct
3 Correct 22 ms 49336 KB Output is correct
4 Correct 22 ms 49236 KB Output is correct
5 Correct 21 ms 49236 KB Output is correct
6 Correct 21 ms 49236 KB Output is correct
7 Correct 21 ms 49236 KB Output is correct
8 Correct 21 ms 49236 KB Output is correct
9 Correct 28 ms 49240 KB Output is correct
10 Correct 26 ms 49228 KB Output is correct
11 Correct 20 ms 49244 KB Output is correct
12 Correct 20 ms 49344 KB Output is correct
13 Correct 22 ms 49364 KB Output is correct
14 Correct 27 ms 49244 KB Output is correct
15 Correct 21 ms 49364 KB Output is correct
16 Correct 22 ms 49356 KB Output is correct
17 Correct 22 ms 49244 KB Output is correct
18 Correct 22 ms 49236 KB Output is correct
19 Correct 20 ms 49252 KB Output is correct
20 Correct 20 ms 49236 KB Output is correct
21 Correct 21 ms 49364 KB Output is correct
22 Correct 21 ms 49424 KB Output is correct
23 Correct 20 ms 49364 KB Output is correct
24 Correct 22 ms 49388 KB Output is correct
25 Correct 22 ms 49372 KB Output is correct
26 Correct 22 ms 49364 KB Output is correct
27 Correct 25 ms 49364 KB Output is correct
28 Correct 23 ms 49368 KB Output is correct
29 Correct 21 ms 49364 KB Output is correct
30 Correct 20 ms 49392 KB Output is correct
31 Correct 20 ms 49416 KB Output is correct
32 Correct 23 ms 49384 KB Output is correct
33 Correct 21 ms 49328 KB Output is correct
34 Correct 22 ms 49272 KB Output is correct
35 Correct 21 ms 49328 KB Output is correct
36 Correct 20 ms 49216 KB Output is correct
37 Correct 22 ms 49264 KB Output is correct
38 Correct 29 ms 49244 KB Output is correct
39 Correct 23 ms 49376 KB Output is correct
40 Correct 23 ms 49868 KB Output is correct
41 Correct 27 ms 50372 KB Output is correct
42 Correct 29 ms 51516 KB Output is correct
43 Correct 32 ms 51600 KB Output is correct
44 Correct 33 ms 51584 KB Output is correct
45 Correct 37 ms 51532 KB Output is correct
46 Correct 38 ms 51424 KB Output is correct
47 Correct 32 ms 50640 KB Output is correct
48 Correct 29 ms 51056 KB Output is correct
49 Correct 31 ms 51128 KB Output is correct
50 Correct 29 ms 51144 KB Output is correct
51 Correct 29 ms 50992 KB Output is correct
52 Correct 31 ms 51008 KB Output is correct
53 Correct 33 ms 51496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 49236 KB Output is correct
2 Correct 24 ms 49216 KB Output is correct
3 Correct 22 ms 49336 KB Output is correct
4 Correct 22 ms 49236 KB Output is correct
5 Correct 21 ms 49236 KB Output is correct
6 Correct 21 ms 49236 KB Output is correct
7 Correct 21 ms 49236 KB Output is correct
8 Correct 21 ms 49236 KB Output is correct
9 Correct 28 ms 49240 KB Output is correct
10 Correct 26 ms 49228 KB Output is correct
11 Correct 20 ms 49244 KB Output is correct
12 Correct 20 ms 49344 KB Output is correct
13 Correct 22 ms 49364 KB Output is correct
14 Correct 27 ms 49244 KB Output is correct
15 Correct 21 ms 49364 KB Output is correct
16 Correct 22 ms 49356 KB Output is correct
17 Correct 22 ms 49244 KB Output is correct
18 Correct 22 ms 49236 KB Output is correct
19 Correct 20 ms 49252 KB Output is correct
20 Correct 20 ms 49236 KB Output is correct
21 Correct 21 ms 49364 KB Output is correct
22 Correct 21 ms 49424 KB Output is correct
23 Correct 20 ms 49364 KB Output is correct
24 Correct 22 ms 49388 KB Output is correct
25 Correct 22 ms 49372 KB Output is correct
26 Correct 22 ms 49364 KB Output is correct
27 Correct 25 ms 49364 KB Output is correct
28 Correct 23 ms 49368 KB Output is correct
29 Correct 21 ms 49364 KB Output is correct
30 Correct 20 ms 49392 KB Output is correct
31 Correct 20 ms 49416 KB Output is correct
32 Correct 23 ms 49384 KB Output is correct
33 Correct 21 ms 49328 KB Output is correct
34 Correct 22 ms 49272 KB Output is correct
35 Correct 21 ms 49328 KB Output is correct
36 Correct 20 ms 49216 KB Output is correct
37 Correct 22 ms 49264 KB Output is correct
38 Correct 29 ms 49244 KB Output is correct
39 Correct 23 ms 49376 KB Output is correct
40 Correct 23 ms 49868 KB Output is correct
41 Correct 27 ms 50372 KB Output is correct
42 Correct 29 ms 51516 KB Output is correct
43 Correct 32 ms 51600 KB Output is correct
44 Correct 33 ms 51584 KB Output is correct
45 Correct 37 ms 51532 KB Output is correct
46 Correct 38 ms 51424 KB Output is correct
47 Correct 32 ms 50640 KB Output is correct
48 Correct 29 ms 51056 KB Output is correct
49 Correct 31 ms 51128 KB Output is correct
50 Correct 29 ms 51144 KB Output is correct
51 Correct 29 ms 50992 KB Output is correct
52 Correct 31 ms 51008 KB Output is correct
53 Correct 33 ms 51496 KB Output is correct
54 Correct 107 ms 58396 KB Output is correct
55 Correct 229 ms 59852 KB Output is correct
56 Runtime error 759 ms 181820 KB Execution killed with signal 6
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 49236 KB Output is correct
2 Correct 24 ms 49216 KB Output is correct
3 Correct 22 ms 49336 KB Output is correct
4 Correct 22 ms 49236 KB Output is correct
5 Correct 21 ms 49236 KB Output is correct
6 Correct 21 ms 49236 KB Output is correct
7 Correct 21 ms 49236 KB Output is correct
8 Correct 21 ms 49236 KB Output is correct
9 Correct 28 ms 49240 KB Output is correct
10 Correct 26 ms 49228 KB Output is correct
11 Correct 20 ms 49364 KB Output is correct
12 Correct 20 ms 49440 KB Output is correct
13 Correct 883 ms 78168 KB Output is correct
14 Correct 1128 ms 81752 KB Output is correct
15 Correct 1301 ms 86752 KB Output is correct
16 Correct 1602 ms 92684 KB Output is correct
17 Correct 1839 ms 99704 KB Output is correct
18 Correct 1870 ms 99804 KB Output is correct
19 Correct 1904 ms 99636 KB Output is correct
20 Correct 25 ms 49236 KB Output is correct
21 Correct 24 ms 49312 KB Output is correct
22 Correct 21 ms 49236 KB Output is correct
23 Correct 21 ms 49332 KB Output is correct
24 Correct 22 ms 49292 KB Output is correct
25 Correct 20 ms 49364 KB Output is correct
26 Correct 25 ms 49380 KB Output is correct
27 Correct 20 ms 49248 KB Output is correct
28 Correct 20 ms 49244 KB Output is correct
29 Correct 20 ms 49344 KB Output is correct
30 Correct 22 ms 49364 KB Output is correct
31 Correct 27 ms 49244 KB Output is correct
32 Correct 21 ms 49364 KB Output is correct
33 Correct 22 ms 49356 KB Output is correct
34 Correct 22 ms 49244 KB Output is correct
35 Correct 22 ms 49236 KB Output is correct
36 Correct 20 ms 49252 KB Output is correct
37 Correct 20 ms 49236 KB Output is correct
38 Correct 21 ms 49364 KB Output is correct
39 Correct 21 ms 49424 KB Output is correct
40 Correct 20 ms 49364 KB Output is correct
41 Correct 22 ms 49388 KB Output is correct
42 Correct 22 ms 49372 KB Output is correct
43 Correct 22 ms 49364 KB Output is correct
44 Correct 25 ms 49364 KB Output is correct
45 Correct 23 ms 49368 KB Output is correct
46 Correct 21 ms 49364 KB Output is correct
47 Correct 20 ms 49392 KB Output is correct
48 Correct 20 ms 49416 KB Output is correct
49 Correct 23 ms 49384 KB Output is correct
50 Correct 21 ms 49328 KB Output is correct
51 Correct 22 ms 49272 KB Output is correct
52 Correct 21 ms 49328 KB Output is correct
53 Correct 20 ms 49216 KB Output is correct
54 Correct 22 ms 49264 KB Output is correct
55 Correct 29 ms 49244 KB Output is correct
56 Correct 23 ms 49376 KB Output is correct
57 Correct 23 ms 49868 KB Output is correct
58 Correct 27 ms 50372 KB Output is correct
59 Correct 29 ms 51516 KB Output is correct
60 Correct 32 ms 51600 KB Output is correct
61 Correct 33 ms 51584 KB Output is correct
62 Correct 37 ms 51532 KB Output is correct
63 Correct 38 ms 51424 KB Output is correct
64 Correct 32 ms 50640 KB Output is correct
65 Correct 29 ms 51056 KB Output is correct
66 Correct 31 ms 51128 KB Output is correct
67 Correct 29 ms 51144 KB Output is correct
68 Correct 29 ms 50992 KB Output is correct
69 Correct 31 ms 51008 KB Output is correct
70 Correct 33 ms 51496 KB Output is correct
71 Correct 107 ms 58396 KB Output is correct
72 Correct 229 ms 59852 KB Output is correct
73 Runtime error 759 ms 181820 KB Execution killed with signal 6
74 Halted 0 ms 0 KB -