# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
770307 | 2023-07-01T05:23:56 Z | Amylopectin | Copy and Paste 3 (JOI22_copypaste3) | C++14 | 3000 ms | 2800 KB |
#include <iostream> #include <stdio.h> #include <vector> using namespace std; const long long mxn = 3e3 + 10; // const long long mxn = 20; char s[mxn] = {}; long long c1,c2,c3,u[mxn] = {},rev[mxn] = {},dp[mxn][mxn] = {}; long long re(long long cl,long long cr) { if(dp[cl][cr] != 0) { return dp[cl][cr]; } long long i,j,k,o,n = cr - cl + 1,cn,cm,cou,cma = 1,fmi = -1,cmi; for(i=cl; i<=cr; i++) { u[i] = 0; } fmi = c1 * n; for(i=n/2; i>0; i--) { cma = 1; for(j=cl; j<=cl+n - i*2; j++) { if(u[j] != i) { cou = 0; cn = j; rev[j] = j; for(k=j+1; k<j+i; k++) { while(1) { if(s[k] == s[cn]) { rev[k] = cn+1; cn++; break; } if(cn == j) { rev[k] = j; break; } cn = rev[cn-1]; } } cn = j+i-1; for(k=j+i-1; k<=cr; k++) { while(1) { if(s[k] == s[cn]) { cn++; break; } if(cn == j) { break; } cn = rev[cn-1]; } if(cn == j+i) { u[k-i+1] = i; cn = rev[cn-1]; } } cn = j+i-1; for(k=j+i-1; k<=cr; k++) { while(1) { if(s[k] == s[cn]) { cn++; break; } if(cn == j) { break; } cn = rev[cn-1]; } if(cn == j+i) { cou ++; cn = j; if(cr-k < i) break; } } // if(fmi == -1) // { // fmi = re(j,j+i-1) + c2 + cou * c3 + c1 * (n-cou*i); // } // else // { cmi = re(j,j+i-1) + c2 + cou * c3 + c1 * (n-cou*i); if(fmi > cmi) { fmi = cmi; } // } // if(cou > cma) // { // cma = cou; // } } } } dp[cl][cr] = fmi; return fmi; } int main() { long long i,j,m,n; scanf("%lld %s %lld %lld %lld",&n,&s,&c1,&c2,&c3); re(0,n-1); printf("%lld",dp[0][n-1]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 284 KB | Output is correct |
3 | Execution timed out | 3064 ms | 2800 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 352 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 304 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 0 ms | 340 KB | Output is correct |
28 | Correct | 0 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 308 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 1 ms | 436 KB | Output is correct |
34 | Correct | 1 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 0 ms | 340 KB | Output is correct |
39 | Correct | 0 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 352 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 304 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 0 ms | 340 KB | Output is correct |
28 | Correct | 0 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 308 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 1 ms | 436 KB | Output is correct |
34 | Correct | 1 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 0 ms | 340 KB | Output is correct |
39 | Correct | 0 ms | 340 KB | Output is correct |
40 | Correct | 16 ms | 544 KB | Output is correct |
41 | Correct | 22 ms | 780 KB | Output is correct |
42 | Correct | 1022 ms | 1112 KB | Output is correct |
43 | Correct | 976 ms | 1172 KB | Output is correct |
44 | Correct | 819 ms | 1244 KB | Output is correct |
45 | Correct | 756 ms | 1156 KB | Output is correct |
46 | Correct | 681 ms | 1136 KB | Output is correct |
47 | Correct | 479 ms | 896 KB | Output is correct |
48 | Correct | 681 ms | 928 KB | Output is correct |
49 | Correct | 691 ms | 1036 KB | Output is correct |
50 | Correct | 650 ms | 1072 KB | Output is correct |
51 | Correct | 452 ms | 1020 KB | Output is correct |
52 | Correct | 519 ms | 940 KB | Output is correct |
53 | Correct | 667 ms | 1320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 352 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 304 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 0 ms | 340 KB | Output is correct |
28 | Correct | 0 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 308 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 1 ms | 436 KB | Output is correct |
34 | Correct | 1 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 0 ms | 340 KB | Output is correct |
39 | Correct | 0 ms | 340 KB | Output is correct |
40 | Correct | 16 ms | 544 KB | Output is correct |
41 | Correct | 22 ms | 780 KB | Output is correct |
42 | Correct | 1022 ms | 1112 KB | Output is correct |
43 | Correct | 976 ms | 1172 KB | Output is correct |
44 | Correct | 819 ms | 1244 KB | Output is correct |
45 | Correct | 756 ms | 1156 KB | Output is correct |
46 | Correct | 681 ms | 1136 KB | Output is correct |
47 | Correct | 479 ms | 896 KB | Output is correct |
48 | Correct | 681 ms | 928 KB | Output is correct |
49 | Correct | 691 ms | 1036 KB | Output is correct |
50 | Correct | 650 ms | 1072 KB | Output is correct |
51 | Correct | 452 ms | 1020 KB | Output is correct |
52 | Correct | 519 ms | 940 KB | Output is correct |
53 | Correct | 667 ms | 1320 KB | Output is correct |
54 | Execution timed out | 3052 ms | 1304 KB | Time limit exceeded |
55 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 284 KB | Output is correct |
13 | Execution timed out | 3064 ms | 2800 KB | Time limit exceeded |
14 | Halted | 0 ms | 0 KB | - |