Submission #1020044

# Submission time Handle Problem Language Result Execution time Memory
1020044 2024-07-11T13:11:47 Z alexdd Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
1318 ms 87788 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++)
    {
        unordered_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;
            int x = mp[s.substr(le,lun)];
            if(x==0) nxt[le][le+lun-1]=-1;
            else nxt[le][le+lun-1]=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 0 ms 2392 KB Output is correct
3 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 419 ms 56056 KB Output is correct
4 Correct 523 ms 63708 KB Output is correct
5 Correct 655 ms 72052 KB Output is correct
6 Correct 805 ms 78672 KB Output is correct
7 Correct 946 ms 84304 KB Output is correct
8 Correct 977 ms 85676 KB Output is correct
9 Correct 1074 ms 84304 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 0 ms 2396 KB Output is correct
16 Correct 1 ms 4444 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 0 ms 2392 KB Output is correct
3 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2652 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 2652 KB Output is correct
32 Correct 1 ms 2656 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 0 ms 2392 KB Output is correct
35 Correct 0 ms 2400 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 2392 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 0 ms 2392 KB Output is correct
3 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2652 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 2652 KB Output is correct
32 Correct 1 ms 2656 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 0 ms 2392 KB Output is correct
35 Correct 0 ms 2400 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 2392 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2908 KB Output is correct
41 Correct 3 ms 4188 KB Output is correct
42 Correct 4 ms 4008 KB Output is correct
43 Correct 4 ms 4188 KB Output is correct
44 Correct 3 ms 4188 KB Output is correct
45 Correct 4 ms 4028 KB Output is correct
46 Correct 4 ms 4188 KB Output is correct
47 Correct 3 ms 4188 KB Output is correct
48 Correct 3 ms 5724 KB Output is correct
49 Correct 4 ms 4184 KB Output is correct
50 Correct 3 ms 4188 KB Output is correct
51 Correct 3 ms 4188 KB Output is correct
52 Correct 3 ms 4188 KB Output is correct
53 Correct 4 ms 4124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2652 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 0 ms 2652 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 2652 KB Output is correct
32 Correct 1 ms 2656 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 0 ms 2392 KB Output is correct
35 Correct 0 ms 2400 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 2392 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2908 KB Output is correct
41 Correct 3 ms 4188 KB Output is correct
42 Correct 4 ms 4008 KB Output is correct
43 Correct 4 ms 4188 KB Output is correct
44 Correct 3 ms 4188 KB Output is correct
45 Correct 4 ms 4028 KB Output is correct
46 Correct 4 ms 4188 KB Output is correct
47 Correct 3 ms 4188 KB Output is correct
48 Correct 3 ms 5724 KB Output is correct
49 Correct 4 ms 4184 KB Output is correct
50 Correct 3 ms 4188 KB Output is correct
51 Correct 3 ms 4188 KB Output is correct
52 Correct 3 ms 4188 KB Output is correct
53 Correct 4 ms 4124 KB Output is correct
54 Correct 20 ms 9820 KB Output is correct
55 Correct 90 ms 21896 KB Output is correct
56 Correct 126 ms 22288 KB Output is correct
57 Correct 126 ms 22472 KB Output is correct
58 Correct 123 ms 22440 KB Output is correct
59 Correct 124 ms 23888 KB Output is correct
60 Correct 123 ms 22356 KB Output is correct
61 Correct 104 ms 22356 KB Output is correct
62 Correct 85 ms 22096 KB Output is correct
63 Correct 127 ms 22356 KB Output is correct
64 Correct 132 ms 22356 KB Output is correct
65 Correct 118 ms 23908 KB Output is correct
66 Correct 111 ms 22356 KB Output is correct
67 Correct 124 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 419 ms 56056 KB Output is correct
14 Correct 523 ms 63708 KB Output is correct
15 Correct 655 ms 72052 KB Output is correct
16 Correct 805 ms 78672 KB Output is correct
17 Correct 946 ms 84304 KB Output is correct
18 Correct 977 ms 85676 KB Output is correct
19 Correct 1074 ms 84304 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 0 ms 2396 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2652 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 0 ms 2652 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 2648 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 0 ms 4444 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 0 ms 2652 KB Output is correct
49 Correct 1 ms 2656 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 0 ms 2392 KB Output is correct
52 Correct 0 ms 2400 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 1 ms 2392 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 1 ms 2908 KB Output is correct
58 Correct 3 ms 4188 KB Output is correct
59 Correct 4 ms 4008 KB Output is correct
60 Correct 4 ms 4188 KB Output is correct
61 Correct 3 ms 4188 KB Output is correct
62 Correct 4 ms 4028 KB Output is correct
63 Correct 4 ms 4188 KB Output is correct
64 Correct 3 ms 4188 KB Output is correct
65 Correct 3 ms 5724 KB Output is correct
66 Correct 4 ms 4184 KB Output is correct
67 Correct 3 ms 4188 KB Output is correct
68 Correct 3 ms 4188 KB Output is correct
69 Correct 3 ms 4188 KB Output is correct
70 Correct 4 ms 4124 KB Output is correct
71 Correct 20 ms 9820 KB Output is correct
72 Correct 90 ms 21896 KB Output is correct
73 Correct 126 ms 22288 KB Output is correct
74 Correct 126 ms 22472 KB Output is correct
75 Correct 123 ms 22440 KB Output is correct
76 Correct 124 ms 23888 KB Output is correct
77 Correct 123 ms 22356 KB Output is correct
78 Correct 104 ms 22356 KB Output is correct
79 Correct 85 ms 22096 KB Output is correct
80 Correct 127 ms 22356 KB Output is correct
81 Correct 132 ms 22356 KB Output is correct
82 Correct 118 ms 23908 KB Output is correct
83 Correct 111 ms 22356 KB Output is correct
84 Correct 124 ms 23892 KB Output is correct
85 Correct 396 ms 46924 KB Output is correct
86 Correct 1298 ms 86140 KB Output is correct
87 Correct 1293 ms 86132 KB Output is correct
88 Correct 1318 ms 86244 KB Output is correct
89 Correct 1283 ms 87716 KB Output is correct
90 Correct 1279 ms 87788 KB Output is correct
91 Correct 999 ms 84672 KB Output is correct
92 Correct 1045 ms 84560 KB Output is correct
93 Correct 1253 ms 86136 KB Output is correct
94 Correct 1261 ms 86308 KB Output is correct
95 Correct 1301 ms 85644 KB Output is correct
96 Correct 1291 ms 87252 KB Output is correct
97 Correct 1296 ms 86140 KB Output is correct