Submission #1020040

# Submission time Handle Problem Language Result Execution time Memory
1020040 2024-07-11T13:10:43 Z alexdd Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
1667 ms 87848 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
int n,a,b,c;
string s;
int dp[2505][2505];
int nxt[2505][2505];
void calc_nxt()
{
    for(int lun=1;lun<=n;lun++)
    {
        map<string,int> mp;
        for(int le=n-lun;le>=0;le--)
        {
            if(le+lun+lun-1<n) mp[s.substr(le+lun,lun)]=le+lun;
            string x = s.substr(le,lun);
            if(mp[x]==0) nxt[le][le+lun-1]=-1;
            else nxt[le][le+lun-1]=mp[x];
        }
    }
}
signed main()
{
    cin>>n>>s>>a>>b>>c;
    calc_nxt();
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            dp[i][j]=INF;
    for(int lun=1;lun<=n;lun++)
    {
        for(int le=0;le+lun-1<n;le++)
        {
            int ri=le+lun-1;
            dp[le][ri] = min(dp[le][ri], (ri-le+1)*a);
            if(ri+1<n) dp[le][ri+1] = min(dp[le][ri+1], dp[le][ri]+a);
            if(le-1>=0) dp[le-1][ri] = min(dp[le-1][ri], dp[le][ri]+a);

            int cur=nxt[le][ri],cnt=1;
            while(cur!=-1)
            {
                cnt++;
                dp[le][cur+lun-1] = min(dp[le][cur+lun-1], dp[le][ri] + b + cnt*c + (((cur+lun-1)-le+1)-cnt*lun)*a);
                cur = nxt[cur][cur+lun-1];
            }
        }
    }
    cout<<dp[0][n-1];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 231 ms 56264 KB Output is correct
4 Correct 288 ms 63916 KB Output is correct
5 Correct 364 ms 70712 KB Output is correct
6 Correct 399 ms 77140 KB Output is correct
7 Correct 492 ms 84212 KB Output is correct
8 Correct 485 ms 84324 KB Output is correct
9 Correct 491 ms 84308 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 0 ms 2652 KB Output is correct
29 Correct 0 ms 2652 KB Output is correct
30 Correct 0 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 0 ms 2492 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 0 ms 2652 KB Output is correct
29 Correct 0 ms 2652 KB Output is correct
30 Correct 0 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 0 ms 2492 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2908 KB Output is correct
41 Correct 2 ms 4184 KB Output is correct
42 Correct 5 ms 5724 KB Output is correct
43 Correct 5 ms 4188 KB Output is correct
44 Correct 6 ms 5720 KB Output is correct
45 Correct 5 ms 4188 KB Output is correct
46 Correct 5 ms 4184 KB Output is correct
47 Correct 4 ms 4024 KB Output is correct
48 Correct 5 ms 4188 KB Output is correct
49 Correct 7 ms 4188 KB Output is correct
50 Correct 5 ms 4188 KB Output is correct
51 Correct 4 ms 5724 KB Output is correct
52 Correct 4 ms 4188 KB Output is correct
53 Correct 5 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 0 ms 2652 KB Output is correct
29 Correct 0 ms 2652 KB Output is correct
30 Correct 0 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 0 ms 2492 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2908 KB Output is correct
41 Correct 2 ms 4184 KB Output is correct
42 Correct 5 ms 5724 KB Output is correct
43 Correct 5 ms 4188 KB Output is correct
44 Correct 6 ms 5720 KB Output is correct
45 Correct 5 ms 4188 KB Output is correct
46 Correct 5 ms 4184 KB Output is correct
47 Correct 4 ms 4024 KB Output is correct
48 Correct 5 ms 4188 KB Output is correct
49 Correct 7 ms 4188 KB Output is correct
50 Correct 5 ms 4188 KB Output is correct
51 Correct 4 ms 5724 KB Output is correct
52 Correct 4 ms 4188 KB Output is correct
53 Correct 5 ms 4188 KB Output is correct
54 Correct 28 ms 9888 KB Output is correct
55 Correct 53 ms 21968 KB Output is correct
56 Correct 159 ms 22632 KB Output is correct
57 Correct 167 ms 24072 KB Output is correct
58 Correct 162 ms 22440 KB Output is correct
59 Correct 162 ms 22540 KB Output is correct
60 Correct 170 ms 22356 KB Output is correct
61 Correct 132 ms 22376 KB Output is correct
62 Correct 50 ms 23632 KB Output is correct
63 Correct 160 ms 22404 KB Output is correct
64 Correct 163 ms 22424 KB Output is correct
65 Correct 149 ms 22612 KB Output is correct
66 Correct 138 ms 22396 KB Output is correct
67 Correct 159 ms 22640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 231 ms 56264 KB Output is correct
14 Correct 288 ms 63916 KB Output is correct
15 Correct 364 ms 70712 KB Output is correct
16 Correct 399 ms 77140 KB Output is correct
17 Correct 492 ms 84212 KB Output is correct
18 Correct 485 ms 84324 KB Output is correct
19 Correct 491 ms 84308 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 0 ms 2652 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 0 ms 2652 KB Output is correct
41 Correct 0 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 0 ms 2652 KB Output is correct
46 Correct 0 ms 2652 KB Output is correct
47 Correct 0 ms 2652 KB Output is correct
48 Correct 1 ms 2652 KB Output is correct
49 Correct 0 ms 2492 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 1 ms 2392 KB Output is correct
52 Correct 1 ms 2392 KB Output is correct
53 Correct 1 ms 2392 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 1 ms 2908 KB Output is correct
58 Correct 2 ms 4184 KB Output is correct
59 Correct 5 ms 5724 KB Output is correct
60 Correct 5 ms 4188 KB Output is correct
61 Correct 6 ms 5720 KB Output is correct
62 Correct 5 ms 4188 KB Output is correct
63 Correct 5 ms 4184 KB Output is correct
64 Correct 4 ms 4024 KB Output is correct
65 Correct 5 ms 4188 KB Output is correct
66 Correct 7 ms 4188 KB Output is correct
67 Correct 5 ms 4188 KB Output is correct
68 Correct 4 ms 5724 KB Output is correct
69 Correct 4 ms 4188 KB Output is correct
70 Correct 5 ms 4188 KB Output is correct
71 Correct 28 ms 9888 KB Output is correct
72 Correct 53 ms 21968 KB Output is correct
73 Correct 159 ms 22632 KB Output is correct
74 Correct 167 ms 24072 KB Output is correct
75 Correct 162 ms 22440 KB Output is correct
76 Correct 162 ms 22540 KB Output is correct
77 Correct 170 ms 22356 KB Output is correct
78 Correct 132 ms 22376 KB Output is correct
79 Correct 50 ms 23632 KB Output is correct
80 Correct 160 ms 22404 KB Output is correct
81 Correct 163 ms 22424 KB Output is correct
82 Correct 149 ms 22612 KB Output is correct
83 Correct 138 ms 22396 KB Output is correct
84 Correct 159 ms 22640 KB Output is correct
85 Correct 484 ms 45288 KB Output is correct
86 Correct 1546 ms 85932 KB Output is correct
87 Correct 1428 ms 86000 KB Output is correct
88 Correct 1472 ms 86060 KB Output is correct
89 Correct 1667 ms 87132 KB Output is correct
90 Correct 1453 ms 87848 KB Output is correct
91 Correct 605 ms 84820 KB Output is correct
92 Correct 554 ms 84560 KB Output is correct
93 Correct 1481 ms 85896 KB Output is correct
94 Correct 1510 ms 86164 KB Output is correct
95 Correct 1398 ms 87064 KB Output is correct
96 Correct 1452 ms 85652 KB Output is correct
97 Correct 1652 ms 85680 KB Output is correct