# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
556190 | 2022-05-02T14:57:54 Z | 600Mihnea | Copy and Paste 3 (JOI22_copypaste3) | C++17 | 1401 ms | 58444 KB |
#include <bits/stdc++.h> bool home = 1; using namespace std; typedef long long ll; const int N=2500+7; const ll INF=(ll)1e18+7; int n; int v[N]; int lcp[N][N]; ll a, b, c, dp[N][N]; signed main() { #ifdef ONLINE_JUDGE home = 0; #endif home=0; if (home) { freopen("I_am_iron_man", "r", stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } cin>>n; { string str; cin>>str; assert((int)str.size()==n); for(int i=1;i<=n;i++){ v[i]=str[i-1]-'a'; assert(0<=v[i]&&v[i]<26); } cin>>a>>b>>c; } for (int i=n;i>=1;i--) { for (int j=n;j>=1;j--) { if (v[i]==v[j]){ lcp[i][j]=1+lcp[i+1][j+1]; } } } for (int l=1;l<=n;l++) { for (int r=l;r<=n;r++) { dp[l][r]=INF; } } for (int l=n;l>=1;l--) { for (int len=1;l+len<=n;len++) { vector<int> pivots; int k=l+len; while (k+len-1<=n) { if (lcp[l][k]>=len) { pivots.push_back(k); k+=len; }else{ k++; } } for (int i=0;i<(int) pivots.size();i++) { int r=pivots[i]+len-1; dp[l][r]=min(dp[l][r],dp[r-len+1][r]+(i+2)*(c-a*len)); } } for (int r=l;r<=n;r++){ dp[l][r]=min(dp[l][r]+a*(r-l+1)+b,min(dp[l+1][r],dp[l][r-1])+a); } } cout<<dp[1][n]<<"\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 328 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 195 ms | 38680 KB | Output is correct |
4 | Correct | 258 ms | 42964 KB | Output is correct |
5 | Correct | 270 ms | 47672 KB | Output is correct |
6 | Correct | 322 ms | 52804 KB | Output is correct |
7 | Correct | 437 ms | 58416 KB | Output is correct |
8 | Correct | 428 ms | 58304 KB | Output is correct |
9 | Correct | 418 ms | 58356 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 328 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 596 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 328 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 456 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 468 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 340 KB | Output is correct |
20 | Correct | 0 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 596 KB | Output is correct |
22 | Correct | 0 ms | 596 KB | Output is correct |
23 | Correct | 1 ms | 468 KB | Output is correct |
24 | Correct | 1 ms | 468 KB | Output is correct |
25 | Correct | 1 ms | 596 KB | Output is correct |
26 | Correct | 1 ms | 468 KB | Output is correct |
27 | Correct | 1 ms | 468 KB | Output is correct |
28 | Correct | 0 ms | 468 KB | Output is correct |
29 | Correct | 1 ms | 596 KB | Output is correct |
30 | Correct | 0 ms | 468 KB | Output is correct |
31 | Correct | 1 ms | 468 KB | Output is correct |
32 | Correct | 1 ms | 596 KB | Output is correct |
33 | Correct | 1 ms | 468 KB | Output is correct |
34 | Correct | 1 ms | 324 KB | Output is correct |
35 | Correct | 1 ms | 340 KB | Output is correct |
36 | Correct | 0 ms | 340 KB | Output is correct |
37 | Correct | 1 ms | 340 KB | Output is correct |
38 | Correct | 1 ms | 340 KB | Output is correct |
39 | Correct | 1 ms | 468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 328 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 456 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 468 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 340 KB | Output is correct |
20 | Correct | 0 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 596 KB | Output is correct |
22 | Correct | 0 ms | 596 KB | Output is correct |
23 | Correct | 1 ms | 468 KB | Output is correct |
24 | Correct | 1 ms | 468 KB | Output is correct |
25 | Correct | 1 ms | 596 KB | Output is correct |
26 | Correct | 1 ms | 468 KB | Output is correct |
27 | Correct | 1 ms | 468 KB | Output is correct |
28 | Correct | 0 ms | 468 KB | Output is correct |
29 | Correct | 1 ms | 596 KB | Output is correct |
30 | Correct | 0 ms | 468 KB | Output is correct |
31 | Correct | 1 ms | 468 KB | Output is correct |
32 | Correct | 1 ms | 596 KB | Output is correct |
33 | Correct | 1 ms | 468 KB | Output is correct |
34 | Correct | 1 ms | 324 KB | Output is correct |
35 | Correct | 1 ms | 340 KB | Output is correct |
36 | Correct | 0 ms | 340 KB | Output is correct |
37 | Correct | 1 ms | 340 KB | Output is correct |
38 | Correct | 1 ms | 340 KB | Output is correct |
39 | Correct | 1 ms | 468 KB | Output is correct |
40 | Correct | 1 ms | 980 KB | Output is correct |
41 | Correct | 2 ms | 2260 KB | Output is correct |
42 | Correct | 3 ms | 2132 KB | Output is correct |
43 | Correct | 3 ms | 2260 KB | Output is correct |
44 | Correct | 3 ms | 2260 KB | Output is correct |
45 | Correct | 2 ms | 2132 KB | Output is correct |
46 | Correct | 2 ms | 2132 KB | Output is correct |
47 | Correct | 3 ms | 2132 KB | Output is correct |
48 | Correct | 3 ms | 2132 KB | Output is correct |
49 | Correct | 3 ms | 2132 KB | Output is correct |
50 | Correct | 2 ms | 2132 KB | Output is correct |
51 | Correct | 3 ms | 2204 KB | Output is correct |
52 | Correct | 3 ms | 2260 KB | Output is correct |
53 | Correct | 2 ms | 2132 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 328 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 456 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 468 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 340 KB | Output is correct |
20 | Correct | 0 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 596 KB | Output is correct |
22 | Correct | 0 ms | 596 KB | Output is correct |
23 | Correct | 1 ms | 468 KB | Output is correct |
24 | Correct | 1 ms | 468 KB | Output is correct |
25 | Correct | 1 ms | 596 KB | Output is correct |
26 | Correct | 1 ms | 468 KB | Output is correct |
27 | Correct | 1 ms | 468 KB | Output is correct |
28 | Correct | 0 ms | 468 KB | Output is correct |
29 | Correct | 1 ms | 596 KB | Output is correct |
30 | Correct | 0 ms | 468 KB | Output is correct |
31 | Correct | 1 ms | 468 KB | Output is correct |
32 | Correct | 1 ms | 596 KB | Output is correct |
33 | Correct | 1 ms | 468 KB | Output is correct |
34 | Correct | 1 ms | 324 KB | Output is correct |
35 | Correct | 1 ms | 340 KB | Output is correct |
36 | Correct | 0 ms | 340 KB | Output is correct |
37 | Correct | 1 ms | 340 KB | Output is correct |
38 | Correct | 1 ms | 340 KB | Output is correct |
39 | Correct | 1 ms | 468 KB | Output is correct |
40 | Correct | 1 ms | 980 KB | Output is correct |
41 | Correct | 2 ms | 2260 KB | Output is correct |
42 | Correct | 3 ms | 2132 KB | Output is correct |
43 | Correct | 3 ms | 2260 KB | Output is correct |
44 | Correct | 3 ms | 2260 KB | Output is correct |
45 | Correct | 2 ms | 2132 KB | Output is correct |
46 | Correct | 2 ms | 2132 KB | Output is correct |
47 | Correct | 3 ms | 2132 KB | Output is correct |
48 | Correct | 3 ms | 2132 KB | Output is correct |
49 | Correct | 3 ms | 2132 KB | Output is correct |
50 | Correct | 2 ms | 2132 KB | Output is correct |
51 | Correct | 3 ms | 2204 KB | Output is correct |
52 | Correct | 3 ms | 2260 KB | Output is correct |
53 | Correct | 2 ms | 2132 KB | Output is correct |
54 | Correct | 13 ms | 5460 KB | Output is correct |
55 | Correct | 57 ms | 16084 KB | Output is correct |
56 | Correct | 103 ms | 16152 KB | Output is correct |
57 | Correct | 104 ms | 16152 KB | Output is correct |
58 | Correct | 101 ms | 16120 KB | Output is correct |
59 | Correct | 97 ms | 16116 KB | Output is correct |
60 | Correct | 95 ms | 15976 KB | Output is correct |
61 | Correct | 82 ms | 15996 KB | Output is correct |
62 | Correct | 50 ms | 16084 KB | Output is correct |
63 | Correct | 88 ms | 15956 KB | Output is correct |
64 | Correct | 89 ms | 16036 KB | Output is correct |
65 | Correct | 83 ms | 16084 KB | Output is correct |
66 | Correct | 80 ms | 16128 KB | Output is correct |
67 | Correct | 96 ms | 15952 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 328 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 195 ms | 38680 KB | Output is correct |
14 | Correct | 258 ms | 42964 KB | Output is correct |
15 | Correct | 270 ms | 47672 KB | Output is correct |
16 | Correct | 322 ms | 52804 KB | Output is correct |
17 | Correct | 437 ms | 58416 KB | Output is correct |
18 | Correct | 428 ms | 58304 KB | Output is correct |
19 | Correct | 418 ms | 58356 KB | Output is correct |
20 | Correct | 0 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 0 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 328 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 596 KB | Output is correct |
27 | Correct | 0 ms | 340 KB | Output is correct |
28 | Correct | 0 ms | 340 KB | Output is correct |
29 | Correct | 0 ms | 468 KB | Output is correct |
30 | Correct | 1 ms | 456 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 468 KB | Output is correct |
33 | Correct | 1 ms | 332 KB | Output is correct |
34 | Correct | 0 ms | 340 KB | Output is correct |
35 | Correct | 1 ms | 340 KB | Output is correct |
36 | Correct | 0 ms | 340 KB | Output is correct |
37 | Correct | 0 ms | 340 KB | Output is correct |
38 | Correct | 1 ms | 596 KB | Output is correct |
39 | Correct | 0 ms | 596 KB | Output is correct |
40 | Correct | 1 ms | 468 KB | Output is correct |
41 | Correct | 1 ms | 468 KB | Output is correct |
42 | Correct | 1 ms | 596 KB | Output is correct |
43 | Correct | 1 ms | 468 KB | Output is correct |
44 | Correct | 1 ms | 468 KB | Output is correct |
45 | Correct | 0 ms | 468 KB | Output is correct |
46 | Correct | 1 ms | 596 KB | Output is correct |
47 | Correct | 0 ms | 468 KB | Output is correct |
48 | Correct | 1 ms | 468 KB | Output is correct |
49 | Correct | 1 ms | 596 KB | Output is correct |
50 | Correct | 1 ms | 468 KB | Output is correct |
51 | Correct | 1 ms | 324 KB | Output is correct |
52 | Correct | 1 ms | 340 KB | Output is correct |
53 | Correct | 0 ms | 340 KB | Output is correct |
54 | Correct | 1 ms | 340 KB | Output is correct |
55 | Correct | 1 ms | 340 KB | Output is correct |
56 | Correct | 1 ms | 468 KB | Output is correct |
57 | Correct | 1 ms | 980 KB | Output is correct |
58 | Correct | 2 ms | 2260 KB | Output is correct |
59 | Correct | 3 ms | 2132 KB | Output is correct |
60 | Correct | 3 ms | 2260 KB | Output is correct |
61 | Correct | 3 ms | 2260 KB | Output is correct |
62 | Correct | 2 ms | 2132 KB | Output is correct |
63 | Correct | 2 ms | 2132 KB | Output is correct |
64 | Correct | 3 ms | 2132 KB | Output is correct |
65 | Correct | 3 ms | 2132 KB | Output is correct |
66 | Correct | 3 ms | 2132 KB | Output is correct |
67 | Correct | 2 ms | 2132 KB | Output is correct |
68 | Correct | 3 ms | 2204 KB | Output is correct |
69 | Correct | 3 ms | 2260 KB | Output is correct |
70 | Correct | 2 ms | 2132 KB | Output is correct |
71 | Correct | 13 ms | 5460 KB | Output is correct |
72 | Correct | 57 ms | 16084 KB | Output is correct |
73 | Correct | 103 ms | 16152 KB | Output is correct |
74 | Correct | 104 ms | 16152 KB | Output is correct |
75 | Correct | 101 ms | 16120 KB | Output is correct |
76 | Correct | 97 ms | 16116 KB | Output is correct |
77 | Correct | 95 ms | 15976 KB | Output is correct |
78 | Correct | 82 ms | 15996 KB | Output is correct |
79 | Correct | 50 ms | 16084 KB | Output is correct |
80 | Correct | 88 ms | 15956 KB | Output is correct |
81 | Correct | 89 ms | 16036 KB | Output is correct |
82 | Correct | 83 ms | 16084 KB | Output is correct |
83 | Correct | 80 ms | 16128 KB | Output is correct |
84 | Correct | 96 ms | 15952 KB | Output is correct |
85 | Correct | 377 ms | 31976 KB | Output is correct |
86 | Correct | 1401 ms | 58344 KB | Output is correct |
87 | Correct | 1351 ms | 58380 KB | Output is correct |
88 | Correct | 1338 ms | 58336 KB | Output is correct |
89 | Correct | 1345 ms | 58276 KB | Output is correct |
90 | Correct | 1313 ms | 58344 KB | Output is correct |
91 | Correct | 573 ms | 58344 KB | Output is correct |
92 | Correct | 370 ms | 58344 KB | Output is correct |
93 | Correct | 1097 ms | 58256 KB | Output is correct |
94 | Correct | 1125 ms | 58420 KB | Output is correct |
95 | Correct | 834 ms | 58352 KB | Output is correct |
96 | Correct | 827 ms | 58444 KB | Output is correct |
97 | Correct | 1328 ms | 58348 KB | Output is correct |