Submission #548917

# Submission time Handle Problem Language Result Execution time Memory
548917 2022-04-14T17:26:54 Z Ronin13 Copy and Paste 3 (JOI22_copypaste3) C++14
30 / 100
1367 ms 225396 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 = 3001 + 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";
    }*/
    vector < vector <ll> > v(n + 1);
    ll cnt[n + 1];
    for(ll r = 1; r <= n; r++){
        for(int i = 1; i <= n; i++)v[i].clear();
        for(int i = 0; i <= n; i++)cnt[i] = 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(ll 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 33 ms 70760 KB Output is correct
2 Correct 40 ms 70840 KB Output is correct
3 Correct 41 ms 70736 KB Output is correct
4 Correct 39 ms 70796 KB Output is correct
5 Correct 33 ms 70804 KB Output is correct
6 Correct 33 ms 70732 KB Output is correct
7 Correct 36 ms 70832 KB Output is correct
8 Correct 32 ms 70804 KB Output is correct
9 Correct 33 ms 70840 KB Output is correct
10 Correct 33 ms 70812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 70868 KB Output is correct
2 Correct 41 ms 70736 KB Output is correct
3 Correct 585 ms 100232 KB Output is correct
4 Correct 736 ms 103756 KB Output is correct
5 Correct 888 ms 108688 KB Output is correct
6 Correct 1000 ms 114928 KB Output is correct
7 Correct 1350 ms 121924 KB Output is correct
8 Correct 1367 ms 121916 KB Output is correct
9 Correct 1313 ms 121972 KB Output is correct
10 Correct 33 ms 70776 KB Output is correct
11 Correct 34 ms 70732 KB Output is correct
12 Correct 36 ms 70796 KB Output is correct
13 Correct 43 ms 70856 KB Output is correct
14 Correct 33 ms 70848 KB Output is correct
15 Correct 32 ms 70860 KB Output is correct
16 Correct 35 ms 70936 KB Output is correct
17 Correct 32 ms 70740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 70760 KB Output is correct
2 Correct 40 ms 70840 KB Output is correct
3 Correct 41 ms 70736 KB Output is correct
4 Correct 39 ms 70796 KB Output is correct
5 Correct 33 ms 70804 KB Output is correct
6 Correct 33 ms 70732 KB Output is correct
7 Correct 36 ms 70832 KB Output is correct
8 Correct 32 ms 70804 KB Output is correct
9 Correct 33 ms 70840 KB Output is correct
10 Correct 33 ms 70812 KB Output is correct
11 Correct 33 ms 70876 KB Output is correct
12 Correct 41 ms 70812 KB Output is correct
13 Correct 41 ms 70828 KB Output is correct
14 Correct 34 ms 70832 KB Output is correct
15 Correct 31 ms 70924 KB Output is correct
16 Correct 32 ms 70868 KB Output is correct
17 Correct 32 ms 70744 KB Output is correct
18 Correct 32 ms 70740 KB Output is correct
19 Correct 33 ms 70772 KB Output is correct
20 Correct 35 ms 70868 KB Output is correct
21 Correct 39 ms 70868 KB Output is correct
22 Correct 33 ms 70916 KB Output is correct
23 Correct 33 ms 70952 KB Output is correct
24 Correct 33 ms 70896 KB Output is correct
25 Correct 36 ms 70896 KB Output is correct
26 Correct 34 ms 70824 KB Output is correct
27 Correct 32 ms 70980 KB Output is correct
28 Correct 33 ms 70904 KB Output is correct
29 Correct 33 ms 70860 KB Output is correct
30 Correct 37 ms 70964 KB Output is correct
31 Correct 34 ms 70860 KB Output is correct
32 Correct 32 ms 70840 KB Output is correct
33 Correct 32 ms 70868 KB Output is correct
34 Correct 33 ms 70740 KB Output is correct
35 Correct 41 ms 70836 KB Output is correct
36 Correct 40 ms 70732 KB Output is correct
37 Correct 36 ms 70860 KB Output is correct
38 Correct 32 ms 70832 KB Output is correct
39 Correct 33 ms 70884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 70760 KB Output is correct
2 Correct 40 ms 70840 KB Output is correct
3 Correct 41 ms 70736 KB Output is correct
4 Correct 39 ms 70796 KB Output is correct
5 Correct 33 ms 70804 KB Output is correct
6 Correct 33 ms 70732 KB Output is correct
7 Correct 36 ms 70832 KB Output is correct
8 Correct 32 ms 70804 KB Output is correct
9 Correct 33 ms 70840 KB Output is correct
10 Correct 33 ms 70812 KB Output is correct
11 Correct 33 ms 70876 KB Output is correct
12 Correct 41 ms 70812 KB Output is correct
13 Correct 41 ms 70828 KB Output is correct
14 Correct 34 ms 70832 KB Output is correct
15 Correct 31 ms 70924 KB Output is correct
16 Correct 32 ms 70868 KB Output is correct
17 Correct 32 ms 70744 KB Output is correct
18 Correct 32 ms 70740 KB Output is correct
19 Correct 33 ms 70772 KB Output is correct
20 Correct 35 ms 70868 KB Output is correct
21 Correct 39 ms 70868 KB Output is correct
22 Correct 33 ms 70916 KB Output is correct
23 Correct 33 ms 70952 KB Output is correct
24 Correct 33 ms 70896 KB Output is correct
25 Correct 36 ms 70896 KB Output is correct
26 Correct 34 ms 70824 KB Output is correct
27 Correct 32 ms 70980 KB Output is correct
28 Correct 33 ms 70904 KB Output is correct
29 Correct 33 ms 70860 KB Output is correct
30 Correct 37 ms 70964 KB Output is correct
31 Correct 34 ms 70860 KB Output is correct
32 Correct 32 ms 70840 KB Output is correct
33 Correct 32 ms 70868 KB Output is correct
34 Correct 33 ms 70740 KB Output is correct
35 Correct 41 ms 70836 KB Output is correct
36 Correct 40 ms 70732 KB Output is correct
37 Correct 36 ms 70860 KB Output is correct
38 Correct 32 ms 70832 KB Output is correct
39 Correct 33 ms 70884 KB Output is correct
40 Correct 32 ms 71364 KB Output is correct
41 Correct 35 ms 71884 KB Output is correct
42 Correct 47 ms 73004 KB Output is correct
43 Correct 40 ms 73100 KB Output is correct
44 Correct 56 ms 73032 KB Output is correct
45 Correct 47 ms 73060 KB Output is correct
46 Correct 50 ms 73036 KB Output is correct
47 Correct 37 ms 72140 KB Output is correct
48 Correct 39 ms 72524 KB Output is correct
49 Correct 40 ms 72760 KB Output is correct
50 Correct 40 ms 72780 KB Output is correct
51 Correct 41 ms 72500 KB Output is correct
52 Correct 41 ms 72524 KB Output is correct
53 Correct 44 ms 73052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 70760 KB Output is correct
2 Correct 40 ms 70840 KB Output is correct
3 Correct 41 ms 70736 KB Output is correct
4 Correct 39 ms 70796 KB Output is correct
5 Correct 33 ms 70804 KB Output is correct
6 Correct 33 ms 70732 KB Output is correct
7 Correct 36 ms 70832 KB Output is correct
8 Correct 32 ms 70804 KB Output is correct
9 Correct 33 ms 70840 KB Output is correct
10 Correct 33 ms 70812 KB Output is correct
11 Correct 33 ms 70876 KB Output is correct
12 Correct 41 ms 70812 KB Output is correct
13 Correct 41 ms 70828 KB Output is correct
14 Correct 34 ms 70832 KB Output is correct
15 Correct 31 ms 70924 KB Output is correct
16 Correct 32 ms 70868 KB Output is correct
17 Correct 32 ms 70744 KB Output is correct
18 Correct 32 ms 70740 KB Output is correct
19 Correct 33 ms 70772 KB Output is correct
20 Correct 35 ms 70868 KB Output is correct
21 Correct 39 ms 70868 KB Output is correct
22 Correct 33 ms 70916 KB Output is correct
23 Correct 33 ms 70952 KB Output is correct
24 Correct 33 ms 70896 KB Output is correct
25 Correct 36 ms 70896 KB Output is correct
26 Correct 34 ms 70824 KB Output is correct
27 Correct 32 ms 70980 KB Output is correct
28 Correct 33 ms 70904 KB Output is correct
29 Correct 33 ms 70860 KB Output is correct
30 Correct 37 ms 70964 KB Output is correct
31 Correct 34 ms 70860 KB Output is correct
32 Correct 32 ms 70840 KB Output is correct
33 Correct 32 ms 70868 KB Output is correct
34 Correct 33 ms 70740 KB Output is correct
35 Correct 41 ms 70836 KB Output is correct
36 Correct 40 ms 70732 KB Output is correct
37 Correct 36 ms 70860 KB Output is correct
38 Correct 32 ms 70832 KB Output is correct
39 Correct 33 ms 70884 KB Output is correct
40 Correct 32 ms 71364 KB Output is correct
41 Correct 35 ms 71884 KB Output is correct
42 Correct 47 ms 73004 KB Output is correct
43 Correct 40 ms 73100 KB Output is correct
44 Correct 56 ms 73032 KB Output is correct
45 Correct 47 ms 73060 KB Output is correct
46 Correct 50 ms 73036 KB Output is correct
47 Correct 37 ms 72140 KB Output is correct
48 Correct 39 ms 72524 KB Output is correct
49 Correct 40 ms 72760 KB Output is correct
50 Correct 40 ms 72780 KB Output is correct
51 Correct 41 ms 72500 KB Output is correct
52 Correct 41 ms 72524 KB Output is correct
53 Correct 44 ms 73052 KB Output is correct
54 Correct 95 ms 79896 KB Output is correct
55 Correct 156 ms 81508 KB Output is correct
56 Runtime error 894 ms 225396 KB Execution killed with signal 6
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 70760 KB Output is correct
2 Correct 40 ms 70840 KB Output is correct
3 Correct 41 ms 70736 KB Output is correct
4 Correct 39 ms 70796 KB Output is correct
5 Correct 33 ms 70804 KB Output is correct
6 Correct 33 ms 70732 KB Output is correct
7 Correct 36 ms 70832 KB Output is correct
8 Correct 32 ms 70804 KB Output is correct
9 Correct 33 ms 70840 KB Output is correct
10 Correct 33 ms 70812 KB Output is correct
11 Correct 34 ms 70868 KB Output is correct
12 Correct 41 ms 70736 KB Output is correct
13 Correct 585 ms 100232 KB Output is correct
14 Correct 736 ms 103756 KB Output is correct
15 Correct 888 ms 108688 KB Output is correct
16 Correct 1000 ms 114928 KB Output is correct
17 Correct 1350 ms 121924 KB Output is correct
18 Correct 1367 ms 121916 KB Output is correct
19 Correct 1313 ms 121972 KB Output is correct
20 Correct 33 ms 70776 KB Output is correct
21 Correct 34 ms 70732 KB Output is correct
22 Correct 36 ms 70796 KB Output is correct
23 Correct 43 ms 70856 KB Output is correct
24 Correct 33 ms 70848 KB Output is correct
25 Correct 32 ms 70860 KB Output is correct
26 Correct 35 ms 70936 KB Output is correct
27 Correct 32 ms 70740 KB Output is correct
28 Correct 33 ms 70876 KB Output is correct
29 Correct 41 ms 70812 KB Output is correct
30 Correct 41 ms 70828 KB Output is correct
31 Correct 34 ms 70832 KB Output is correct
32 Correct 31 ms 70924 KB Output is correct
33 Correct 32 ms 70868 KB Output is correct
34 Correct 32 ms 70744 KB Output is correct
35 Correct 32 ms 70740 KB Output is correct
36 Correct 33 ms 70772 KB Output is correct
37 Correct 35 ms 70868 KB Output is correct
38 Correct 39 ms 70868 KB Output is correct
39 Correct 33 ms 70916 KB Output is correct
40 Correct 33 ms 70952 KB Output is correct
41 Correct 33 ms 70896 KB Output is correct
42 Correct 36 ms 70896 KB Output is correct
43 Correct 34 ms 70824 KB Output is correct
44 Correct 32 ms 70980 KB Output is correct
45 Correct 33 ms 70904 KB Output is correct
46 Correct 33 ms 70860 KB Output is correct
47 Correct 37 ms 70964 KB Output is correct
48 Correct 34 ms 70860 KB Output is correct
49 Correct 32 ms 70840 KB Output is correct
50 Correct 32 ms 70868 KB Output is correct
51 Correct 33 ms 70740 KB Output is correct
52 Correct 41 ms 70836 KB Output is correct
53 Correct 40 ms 70732 KB Output is correct
54 Correct 36 ms 70860 KB Output is correct
55 Correct 32 ms 70832 KB Output is correct
56 Correct 33 ms 70884 KB Output is correct
57 Correct 32 ms 71364 KB Output is correct
58 Correct 35 ms 71884 KB Output is correct
59 Correct 47 ms 73004 KB Output is correct
60 Correct 40 ms 73100 KB Output is correct
61 Correct 56 ms 73032 KB Output is correct
62 Correct 47 ms 73060 KB Output is correct
63 Correct 50 ms 73036 KB Output is correct
64 Correct 37 ms 72140 KB Output is correct
65 Correct 39 ms 72524 KB Output is correct
66 Correct 40 ms 72760 KB Output is correct
67 Correct 40 ms 72780 KB Output is correct
68 Correct 41 ms 72500 KB Output is correct
69 Correct 41 ms 72524 KB Output is correct
70 Correct 44 ms 73052 KB Output is correct
71 Correct 95 ms 79896 KB Output is correct
72 Correct 156 ms 81508 KB Output is correct
73 Runtime error 894 ms 225396 KB Execution killed with signal 6
74 Halted 0 ms 0 KB -