Submission #950521

# Submission time Handle Problem Language Result Execution time Memory
950521 2024-03-20T11:37:48 Z hotboy2703 Copy and Paste 3 (JOI22_copypaste3) C++14
30 / 100
3000 ms 134104 KB
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
#define MP make_pair
ll t;
string s;
ll a,b,c;
ll n;
const ll MAXN = 2500;
ll dp[MAXN+10][MAXN+10];
ll type[MAXN+10][MAXN+10];
ll nxt[MAXN+10][MAXN+10];
vector <ll> all[MAXN+10];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
    cin>>t;
//    while (t--){
        cin>>s;
        cin>>a>>b>>c;
        n = sz(s);
        s = "x" + s;
        for (ll k = 1;k <= n;k ++){
            ll ptr = 1;
            for (ll l = 1,r = k; r <= n; l++,r++){
                for (ll l1 = 1,r1 = k; l1 < l; l1++,r1++){
                    bool ok = 1;
                    for (ll j = 0;j < k;j ++){
                        if (s[j+l1] != s[j+l])ok = 0;
                    }
                    if (ok){type[k][l] = type[k][l1];break;}
                }
                if (type[k][l] == 0)type[k][l] = ptr++;
            }
        }
        for (ll k = 1;k <= n;k ++){
            for (ll i = 1;i <= n;i ++)all[i].clear();
            for (ll l = 1,r = k; r <= n; l++,r++){
                all[type[k][l]].push_back(l);
            }
            for (ll i = 1;i <= n;i ++){
                for (ll j = 0,ptr = 0;j < sz(all[i]);j ++){
                    while (ptr < sz(all[i]) && all[i][j] + k > all[i][ptr])ptr++;
                    if (ptr < sz(all[i]))nxt[k][all[i][j]] = all[i][ptr];
                    else nxt[k][all[i][j]] = -1;
                }
            }
//            for (ll l = 1,r = k; r <= n; l++,r++){
//                cout<<nxt[k][l]<<' ';
//            }
//            cout<<'\n';
        }
        for (ll k = 1;k <= n;k ++){
            for (ll l = 1,r = k; r <= n; l++,r++){
                dp[l][r] = (r-l+1)*a;
            }
        }
        for (ll k = 1;k <= n;k ++){
            for (ll l = 1,r = k; r <= n; l++,r++){
                if (l > 1)dp[l-1][r] = min(dp[l-1][r],dp[l][r]+a);
                if (r < n)dp[l][r+1] = min(dp[l][r+1],dp[l][r]+a);
                ll cur = l;
                ll cnt = 1;
                while (1){
                    cur = nxt[k][cur];
                    cnt++;
                    if (cur==-1)break;
                    dp[l][cur + k - 1] = min(dp[l][cur + k - 1],dp[l][r] + b + c * cnt + (cur+k-1-l+1-cnt*k)*a);
                }
            }
        }
//        cout<<dp[3][3]<<'\n';
        cout<<dp[1][n]<<'\n';
//    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2572 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 791 ms 99600 KB Output is correct
4 Correct 943 ms 106616 KB Output is correct
5 Correct 1226 ms 118424 KB Output is correct
6 Correct 1615 ms 129180 KB Output is correct
7 Correct 1976 ms 134048 KB Output is correct
8 Correct 1923 ms 133948 KB Output is correct
9 Correct 1948 ms 134104 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2608 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2572 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 2576 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4784 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4696 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4784 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4696 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2572 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2572 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 2576 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4784 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4696 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4784 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4696 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2572 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 3 ms 4952 KB Output is correct
41 Correct 3 ms 9564 KB Output is correct
42 Correct 50 ms 9556 KB Output is correct
43 Correct 47 ms 9568 KB Output is correct
44 Correct 55 ms 9556 KB Output is correct
45 Correct 47 ms 9668 KB Output is correct
46 Correct 56 ms 9572 KB Output is correct
47 Correct 13 ms 9564 KB Output is correct
48 Correct 29 ms 9564 KB Output is correct
49 Correct 50 ms 9516 KB Output is correct
50 Correct 39 ms 9712 KB Output is correct
51 Correct 29 ms 9564 KB Output is correct
52 Correct 39 ms 9484 KB Output is correct
53 Correct 48 ms 9552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2572 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 2576 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4784 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4696 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4784 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4696 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2572 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 3 ms 4952 KB Output is correct
41 Correct 3 ms 9564 KB Output is correct
42 Correct 50 ms 9556 KB Output is correct
43 Correct 47 ms 9568 KB Output is correct
44 Correct 55 ms 9556 KB Output is correct
45 Correct 47 ms 9668 KB Output is correct
46 Correct 56 ms 9572 KB Output is correct
47 Correct 13 ms 9564 KB Output is correct
48 Correct 29 ms 9564 KB Output is correct
49 Correct 50 ms 9516 KB Output is correct
50 Correct 39 ms 9712 KB Output is correct
51 Correct 29 ms 9564 KB Output is correct
52 Correct 39 ms 9484 KB Output is correct
53 Correct 48 ms 9552 KB Output is correct
54 Correct 1185 ms 23628 KB Output is correct
55 Correct 143 ms 51940 KB Output is correct
56 Execution timed out 3054 ms 2100 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2572 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 791 ms 99600 KB Output is correct
14 Correct 943 ms 106616 KB Output is correct
15 Correct 1226 ms 118424 KB Output is correct
16 Correct 1615 ms 129180 KB Output is correct
17 Correct 1976 ms 134048 KB Output is correct
18 Correct 1923 ms 133948 KB Output is correct
19 Correct 1948 ms 134104 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2608 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 2 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 2576 KB Output is correct
38 Correct 1 ms 4696 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4784 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4700 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4696 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4784 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 1 ms 4696 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2572 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4700 KB Output is correct
56 Correct 1 ms 4700 KB Output is correct
57 Correct 3 ms 4952 KB Output is correct
58 Correct 3 ms 9564 KB Output is correct
59 Correct 50 ms 9556 KB Output is correct
60 Correct 47 ms 9568 KB Output is correct
61 Correct 55 ms 9556 KB Output is correct
62 Correct 47 ms 9668 KB Output is correct
63 Correct 56 ms 9572 KB Output is correct
64 Correct 13 ms 9564 KB Output is correct
65 Correct 29 ms 9564 KB Output is correct
66 Correct 50 ms 9516 KB Output is correct
67 Correct 39 ms 9712 KB Output is correct
68 Correct 29 ms 9564 KB Output is correct
69 Correct 39 ms 9484 KB Output is correct
70 Correct 48 ms 9552 KB Output is correct
71 Correct 1185 ms 23628 KB Output is correct
72 Correct 143 ms 51940 KB Output is correct
73 Execution timed out 3054 ms 2100 KB Time limit exceeded
74 Halted 0 ms 0 KB -