#include <bits/stdc++.h>
using namespace std;
char arr[2505];
long long A,B,C;
long long mem[2505*1305];
int ct = 1;
struct node{
int nid, len;
vector<int> vals;
node*ch[26];
vector<int> decomp[15];
node(int _len){
nid = ct++;
len = _len;
for (int x = 0; x<26; x++){
ch[x] = 0;
}
}
void construct(){
//printf("call construct len %lld\n",len);
for (int x = 0; x<vals.size(); x++){
decomp[0].push_back(lower_bound(vals.begin(),vals.end(),vals[x]+len)-vals.begin());
}
decomp[0].push_back(vals.size());
for (int x = 1; x<15; x++){
for (int y = 0; y<=vals.size(); y++){
decomp[x].push_back(decomp[x-1][decomp[x-1][y]]);
}
}
}
void constructall(){
construct();
for (int x = 0; x<26; x++){
if (ch[x]!=0){
ch[x]->constructall();
}
}
}
int cntocc(int st, int en){
//printf("call cntocc %lld %lld, len %lld\n",st,en,len);
int cur = lower_bound(vals.begin(),vals.end(),st)-vals.begin();
int ans = 1;
int r = upper_bound(vals.begin(),vals.end(),en-len)-vals.begin();
for (int x = 14; x>=0; x--){
if (decomp[x][cur]<r){
ans += (1<<x);
cur = decomp[x][cur];
}
}
return ans;
}
}*rt;
node* pt[2505][2505];
int cntocc(int a, int b, int st, int en){
return pt[a][b]->cntocc(st,en);
}
long long func(int a, int b){
if (a==b) return 0;
if (mem[pt[a][b]->nid]!=-1) return mem[pt[a][b]->nid];
long long ans = func(a+1,b)+A;
for (int x = 1; x<b-a; x++){
long long t = func(a,a+x);
int t2 = cntocc(a,a+x,a,b);
ans = min(ans,t+B+t2*C+(b-a-x*t2)*A);
if (t2==1) break;
}
//printf("func %lld %lld = %lld\n",a,b,ans);
return mem[pt[a][b]->nid] = ans;
}
main(){
int n;
scanf("%d",&n);
for (int x = 0; x<n; x++){
scanf(" %c",&arr[x]);
}
scanf("%lld%lld%lld",&A,&B,&C);
memset(mem,-1,sizeof(mem));
for (int x = 0; x<n; x++){
if (rt==0){
rt = new node(0);
}
node *cur = rt;
for (int y = x+1; y<=n; y++){
if (cur->ch[arr[y-1]-'a']==0){
cur->ch[arr[y-1]-'a'] = new node(y-x);
}
cur = cur->ch[arr[y-1]-'a'];
cur->vals.push_back(x);
pt[x][y] = cur;
}
}
rt->constructall();
printf("%lld",func(0,n));
}
Compilation message
copypaste3.cpp: In member function 'void node::construct()':
copypaste3.cpp:23:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int x = 0; x<vals.size(); x++){
| ~^~~~~~~~~~~~
copypaste3.cpp:28:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int y = 0; y<=vals.size(); y++){
| ~^~~~~~~~~~~~~
copypaste3.cpp: At global scope:
copypaste3.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
77 | main(){
| ^~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
copypaste3.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | scanf(" %c",&arr[x]);
| ~~~~~^~~~~~~~~~~~~~~
copypaste3.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | scanf("%lld%lld%lld",&A,&B,&C);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
25812 KB |
Output is correct |
2 |
Correct |
11 ms |
25812 KB |
Output is correct |
3 |
Correct |
11 ms |
25924 KB |
Output is correct |
4 |
Correct |
11 ms |
25792 KB |
Output is correct |
5 |
Correct |
11 ms |
25812 KB |
Output is correct |
6 |
Correct |
12 ms |
25812 KB |
Output is correct |
7 |
Correct |
12 ms |
25812 KB |
Output is correct |
8 |
Correct |
11 ms |
25840 KB |
Output is correct |
9 |
Correct |
13 ms |
25904 KB |
Output is correct |
10 |
Correct |
13 ms |
25812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
25940 KB |
Output is correct |
2 |
Correct |
11 ms |
25812 KB |
Output is correct |
3 |
Correct |
406 ms |
195188 KB |
Output is correct |
4 |
Correct |
525 ms |
217372 KB |
Output is correct |
5 |
Correct |
563 ms |
247564 KB |
Output is correct |
6 |
Correct |
673 ms |
286484 KB |
Output is correct |
7 |
Correct |
796 ms |
331104 KB |
Output is correct |
8 |
Correct |
806 ms |
331068 KB |
Output is correct |
9 |
Correct |
823 ms |
331008 KB |
Output is correct |
10 |
Correct |
11 ms |
25812 KB |
Output is correct |
11 |
Correct |
14 ms |
25804 KB |
Output is correct |
12 |
Correct |
11 ms |
25812 KB |
Output is correct |
13 |
Correct |
11 ms |
25884 KB |
Output is correct |
14 |
Correct |
14 ms |
25868 KB |
Output is correct |
15 |
Correct |
13 ms |
25976 KB |
Output is correct |
16 |
Correct |
12 ms |
26068 KB |
Output is correct |
17 |
Correct |
11 ms |
25812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
25812 KB |
Output is correct |
2 |
Correct |
11 ms |
25812 KB |
Output is correct |
3 |
Correct |
11 ms |
25924 KB |
Output is correct |
4 |
Correct |
11 ms |
25792 KB |
Output is correct |
5 |
Correct |
11 ms |
25812 KB |
Output is correct |
6 |
Correct |
12 ms |
25812 KB |
Output is correct |
7 |
Correct |
12 ms |
25812 KB |
Output is correct |
8 |
Correct |
11 ms |
25840 KB |
Output is correct |
9 |
Correct |
13 ms |
25904 KB |
Output is correct |
10 |
Correct |
13 ms |
25812 KB |
Output is correct |
11 |
Correct |
12 ms |
25988 KB |
Output is correct |
12 |
Correct |
11 ms |
25960 KB |
Output is correct |
13 |
Correct |
11 ms |
26068 KB |
Output is correct |
14 |
Correct |
10 ms |
25940 KB |
Output is correct |
15 |
Correct |
12 ms |
26136 KB |
Output is correct |
16 |
Correct |
12 ms |
25940 KB |
Output is correct |
17 |
Correct |
11 ms |
25880 KB |
Output is correct |
18 |
Correct |
12 ms |
25812 KB |
Output is correct |
19 |
Correct |
13 ms |
25940 KB |
Output is correct |
20 |
Correct |
12 ms |
25812 KB |
Output is correct |
21 |
Correct |
11 ms |
26068 KB |
Output is correct |
22 |
Correct |
13 ms |
26324 KB |
Output is correct |
23 |
Correct |
13 ms |
26428 KB |
Output is correct |
24 |
Correct |
13 ms |
26384 KB |
Output is correct |
25 |
Correct |
13 ms |
26472 KB |
Output is correct |
26 |
Correct |
15 ms |
26452 KB |
Output is correct |
27 |
Correct |
12 ms |
26068 KB |
Output is correct |
28 |
Correct |
12 ms |
26096 KB |
Output is correct |
29 |
Correct |
12 ms |
26328 KB |
Output is correct |
30 |
Correct |
12 ms |
26340 KB |
Output is correct |
31 |
Correct |
12 ms |
26296 KB |
Output is correct |
32 |
Correct |
12 ms |
26324 KB |
Output is correct |
33 |
Correct |
12 ms |
26452 KB |
Output is correct |
34 |
Correct |
11 ms |
25812 KB |
Output is correct |
35 |
Correct |
11 ms |
25812 KB |
Output is correct |
36 |
Correct |
12 ms |
25812 KB |
Output is correct |
37 |
Correct |
12 ms |
25940 KB |
Output is correct |
38 |
Correct |
12 ms |
25940 KB |
Output is correct |
39 |
Correct |
12 ms |
26072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
25812 KB |
Output is correct |
2 |
Correct |
11 ms |
25812 KB |
Output is correct |
3 |
Correct |
11 ms |
25924 KB |
Output is correct |
4 |
Correct |
11 ms |
25792 KB |
Output is correct |
5 |
Correct |
11 ms |
25812 KB |
Output is correct |
6 |
Correct |
12 ms |
25812 KB |
Output is correct |
7 |
Correct |
12 ms |
25812 KB |
Output is correct |
8 |
Correct |
11 ms |
25840 KB |
Output is correct |
9 |
Correct |
13 ms |
25904 KB |
Output is correct |
10 |
Correct |
13 ms |
25812 KB |
Output is correct |
11 |
Correct |
12 ms |
25988 KB |
Output is correct |
12 |
Correct |
11 ms |
25960 KB |
Output is correct |
13 |
Correct |
11 ms |
26068 KB |
Output is correct |
14 |
Correct |
10 ms |
25940 KB |
Output is correct |
15 |
Correct |
12 ms |
26136 KB |
Output is correct |
16 |
Correct |
12 ms |
25940 KB |
Output is correct |
17 |
Correct |
11 ms |
25880 KB |
Output is correct |
18 |
Correct |
12 ms |
25812 KB |
Output is correct |
19 |
Correct |
13 ms |
25940 KB |
Output is correct |
20 |
Correct |
12 ms |
25812 KB |
Output is correct |
21 |
Correct |
11 ms |
26068 KB |
Output is correct |
22 |
Correct |
13 ms |
26324 KB |
Output is correct |
23 |
Correct |
13 ms |
26428 KB |
Output is correct |
24 |
Correct |
13 ms |
26384 KB |
Output is correct |
25 |
Correct |
13 ms |
26472 KB |
Output is correct |
26 |
Correct |
15 ms |
26452 KB |
Output is correct |
27 |
Correct |
12 ms |
26068 KB |
Output is correct |
28 |
Correct |
12 ms |
26096 KB |
Output is correct |
29 |
Correct |
12 ms |
26328 KB |
Output is correct |
30 |
Correct |
12 ms |
26340 KB |
Output is correct |
31 |
Correct |
12 ms |
26296 KB |
Output is correct |
32 |
Correct |
12 ms |
26324 KB |
Output is correct |
33 |
Correct |
12 ms |
26452 KB |
Output is correct |
34 |
Correct |
11 ms |
25812 KB |
Output is correct |
35 |
Correct |
11 ms |
25812 KB |
Output is correct |
36 |
Correct |
12 ms |
25812 KB |
Output is correct |
37 |
Correct |
12 ms |
25940 KB |
Output is correct |
38 |
Correct |
12 ms |
25940 KB |
Output is correct |
39 |
Correct |
12 ms |
26072 KB |
Output is correct |
40 |
Correct |
22 ms |
29780 KB |
Output is correct |
41 |
Correct |
18 ms |
28812 KB |
Output is correct |
42 |
Correct |
44 ms |
47612 KB |
Output is correct |
43 |
Correct |
42 ms |
48072 KB |
Output is correct |
44 |
Correct |
41 ms |
48424 KB |
Output is correct |
45 |
Correct |
41 ms |
48584 KB |
Output is correct |
46 |
Correct |
40 ms |
48612 KB |
Output is correct |
47 |
Correct |
23 ms |
32780 KB |
Output is correct |
48 |
Correct |
34 ms |
39636 KB |
Output is correct |
49 |
Correct |
36 ms |
42996 KB |
Output is correct |
50 |
Correct |
36 ms |
43340 KB |
Output is correct |
51 |
Correct |
31 ms |
38732 KB |
Output is correct |
52 |
Correct |
34 ms |
38860 KB |
Output is correct |
53 |
Correct |
43 ms |
48584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
25812 KB |
Output is correct |
2 |
Correct |
11 ms |
25812 KB |
Output is correct |
3 |
Correct |
11 ms |
25924 KB |
Output is correct |
4 |
Correct |
11 ms |
25792 KB |
Output is correct |
5 |
Correct |
11 ms |
25812 KB |
Output is correct |
6 |
Correct |
12 ms |
25812 KB |
Output is correct |
7 |
Correct |
12 ms |
25812 KB |
Output is correct |
8 |
Correct |
11 ms |
25840 KB |
Output is correct |
9 |
Correct |
13 ms |
25904 KB |
Output is correct |
10 |
Correct |
13 ms |
25812 KB |
Output is correct |
11 |
Correct |
12 ms |
25988 KB |
Output is correct |
12 |
Correct |
11 ms |
25960 KB |
Output is correct |
13 |
Correct |
11 ms |
26068 KB |
Output is correct |
14 |
Correct |
10 ms |
25940 KB |
Output is correct |
15 |
Correct |
12 ms |
26136 KB |
Output is correct |
16 |
Correct |
12 ms |
25940 KB |
Output is correct |
17 |
Correct |
11 ms |
25880 KB |
Output is correct |
18 |
Correct |
12 ms |
25812 KB |
Output is correct |
19 |
Correct |
13 ms |
25940 KB |
Output is correct |
20 |
Correct |
12 ms |
25812 KB |
Output is correct |
21 |
Correct |
11 ms |
26068 KB |
Output is correct |
22 |
Correct |
13 ms |
26324 KB |
Output is correct |
23 |
Correct |
13 ms |
26428 KB |
Output is correct |
24 |
Correct |
13 ms |
26384 KB |
Output is correct |
25 |
Correct |
13 ms |
26472 KB |
Output is correct |
26 |
Correct |
15 ms |
26452 KB |
Output is correct |
27 |
Correct |
12 ms |
26068 KB |
Output is correct |
28 |
Correct |
12 ms |
26096 KB |
Output is correct |
29 |
Correct |
12 ms |
26328 KB |
Output is correct |
30 |
Correct |
12 ms |
26340 KB |
Output is correct |
31 |
Correct |
12 ms |
26296 KB |
Output is correct |
32 |
Correct |
12 ms |
26324 KB |
Output is correct |
33 |
Correct |
12 ms |
26452 KB |
Output is correct |
34 |
Correct |
11 ms |
25812 KB |
Output is correct |
35 |
Correct |
11 ms |
25812 KB |
Output is correct |
36 |
Correct |
12 ms |
25812 KB |
Output is correct |
37 |
Correct |
12 ms |
25940 KB |
Output is correct |
38 |
Correct |
12 ms |
25940 KB |
Output is correct |
39 |
Correct |
12 ms |
26072 KB |
Output is correct |
40 |
Correct |
22 ms |
29780 KB |
Output is correct |
41 |
Correct |
18 ms |
28812 KB |
Output is correct |
42 |
Correct |
44 ms |
47612 KB |
Output is correct |
43 |
Correct |
42 ms |
48072 KB |
Output is correct |
44 |
Correct |
41 ms |
48424 KB |
Output is correct |
45 |
Correct |
41 ms |
48584 KB |
Output is correct |
46 |
Correct |
40 ms |
48612 KB |
Output is correct |
47 |
Correct |
23 ms |
32780 KB |
Output is correct |
48 |
Correct |
34 ms |
39636 KB |
Output is correct |
49 |
Correct |
36 ms |
42996 KB |
Output is correct |
50 |
Correct |
36 ms |
43340 KB |
Output is correct |
51 |
Correct |
31 ms |
38732 KB |
Output is correct |
52 |
Correct |
34 ms |
38860 KB |
Output is correct |
53 |
Correct |
43 ms |
48584 KB |
Output is correct |
54 |
Correct |
177 ms |
134744 KB |
Output is correct |
55 |
Correct |
122 ms |
77104 KB |
Output is correct |
56 |
Correct |
747 ms |
573248 KB |
Output is correct |
57 |
Correct |
751 ms |
576852 KB |
Output is correct |
58 |
Correct |
961 ms |
579444 KB |
Output is correct |
59 |
Correct |
808 ms |
580252 KB |
Output is correct |
60 |
Correct |
784 ms |
580820 KB |
Output is correct |
61 |
Correct |
590 ms |
275624 KB |
Output is correct |
62 |
Correct |
151 ms |
83616 KB |
Output is correct |
63 |
Correct |
720 ms |
448328 KB |
Output is correct |
64 |
Correct |
691 ms |
452252 KB |
Output is correct |
65 |
Correct |
728 ms |
314912 KB |
Output is correct |
66 |
Correct |
728 ms |
314924 KB |
Output is correct |
67 |
Correct |
762 ms |
580912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
25812 KB |
Output is correct |
2 |
Correct |
11 ms |
25812 KB |
Output is correct |
3 |
Correct |
11 ms |
25924 KB |
Output is correct |
4 |
Correct |
11 ms |
25792 KB |
Output is correct |
5 |
Correct |
11 ms |
25812 KB |
Output is correct |
6 |
Correct |
12 ms |
25812 KB |
Output is correct |
7 |
Correct |
12 ms |
25812 KB |
Output is correct |
8 |
Correct |
11 ms |
25840 KB |
Output is correct |
9 |
Correct |
13 ms |
25904 KB |
Output is correct |
10 |
Correct |
13 ms |
25812 KB |
Output is correct |
11 |
Correct |
12 ms |
25940 KB |
Output is correct |
12 |
Correct |
11 ms |
25812 KB |
Output is correct |
13 |
Correct |
406 ms |
195188 KB |
Output is correct |
14 |
Correct |
525 ms |
217372 KB |
Output is correct |
15 |
Correct |
563 ms |
247564 KB |
Output is correct |
16 |
Correct |
673 ms |
286484 KB |
Output is correct |
17 |
Correct |
796 ms |
331104 KB |
Output is correct |
18 |
Correct |
806 ms |
331068 KB |
Output is correct |
19 |
Correct |
823 ms |
331008 KB |
Output is correct |
20 |
Correct |
11 ms |
25812 KB |
Output is correct |
21 |
Correct |
14 ms |
25804 KB |
Output is correct |
22 |
Correct |
11 ms |
25812 KB |
Output is correct |
23 |
Correct |
11 ms |
25884 KB |
Output is correct |
24 |
Correct |
14 ms |
25868 KB |
Output is correct |
25 |
Correct |
13 ms |
25976 KB |
Output is correct |
26 |
Correct |
12 ms |
26068 KB |
Output is correct |
27 |
Correct |
11 ms |
25812 KB |
Output is correct |
28 |
Correct |
12 ms |
25988 KB |
Output is correct |
29 |
Correct |
11 ms |
25960 KB |
Output is correct |
30 |
Correct |
11 ms |
26068 KB |
Output is correct |
31 |
Correct |
10 ms |
25940 KB |
Output is correct |
32 |
Correct |
12 ms |
26136 KB |
Output is correct |
33 |
Correct |
12 ms |
25940 KB |
Output is correct |
34 |
Correct |
11 ms |
25880 KB |
Output is correct |
35 |
Correct |
12 ms |
25812 KB |
Output is correct |
36 |
Correct |
13 ms |
25940 KB |
Output is correct |
37 |
Correct |
12 ms |
25812 KB |
Output is correct |
38 |
Correct |
11 ms |
26068 KB |
Output is correct |
39 |
Correct |
13 ms |
26324 KB |
Output is correct |
40 |
Correct |
13 ms |
26428 KB |
Output is correct |
41 |
Correct |
13 ms |
26384 KB |
Output is correct |
42 |
Correct |
13 ms |
26472 KB |
Output is correct |
43 |
Correct |
15 ms |
26452 KB |
Output is correct |
44 |
Correct |
12 ms |
26068 KB |
Output is correct |
45 |
Correct |
12 ms |
26096 KB |
Output is correct |
46 |
Correct |
12 ms |
26328 KB |
Output is correct |
47 |
Correct |
12 ms |
26340 KB |
Output is correct |
48 |
Correct |
12 ms |
26296 KB |
Output is correct |
49 |
Correct |
12 ms |
26324 KB |
Output is correct |
50 |
Correct |
12 ms |
26452 KB |
Output is correct |
51 |
Correct |
11 ms |
25812 KB |
Output is correct |
52 |
Correct |
11 ms |
25812 KB |
Output is correct |
53 |
Correct |
12 ms |
25812 KB |
Output is correct |
54 |
Correct |
12 ms |
25940 KB |
Output is correct |
55 |
Correct |
12 ms |
25940 KB |
Output is correct |
56 |
Correct |
12 ms |
26072 KB |
Output is correct |
57 |
Correct |
22 ms |
29780 KB |
Output is correct |
58 |
Correct |
18 ms |
28812 KB |
Output is correct |
59 |
Correct |
44 ms |
47612 KB |
Output is correct |
60 |
Correct |
42 ms |
48072 KB |
Output is correct |
61 |
Correct |
41 ms |
48424 KB |
Output is correct |
62 |
Correct |
41 ms |
48584 KB |
Output is correct |
63 |
Correct |
40 ms |
48612 KB |
Output is correct |
64 |
Correct |
23 ms |
32780 KB |
Output is correct |
65 |
Correct |
34 ms |
39636 KB |
Output is correct |
66 |
Correct |
36 ms |
42996 KB |
Output is correct |
67 |
Correct |
36 ms |
43340 KB |
Output is correct |
68 |
Correct |
31 ms |
38732 KB |
Output is correct |
69 |
Correct |
34 ms |
38860 KB |
Output is correct |
70 |
Correct |
43 ms |
48584 KB |
Output is correct |
71 |
Correct |
177 ms |
134744 KB |
Output is correct |
72 |
Correct |
122 ms |
77104 KB |
Output is correct |
73 |
Correct |
747 ms |
573248 KB |
Output is correct |
74 |
Correct |
751 ms |
576852 KB |
Output is correct |
75 |
Correct |
961 ms |
579444 KB |
Output is correct |
76 |
Correct |
808 ms |
580252 KB |
Output is correct |
77 |
Correct |
784 ms |
580820 KB |
Output is correct |
78 |
Correct |
590 ms |
275624 KB |
Output is correct |
79 |
Correct |
151 ms |
83616 KB |
Output is correct |
80 |
Correct |
720 ms |
448328 KB |
Output is correct |
81 |
Correct |
691 ms |
452252 KB |
Output is correct |
82 |
Correct |
728 ms |
314912 KB |
Output is correct |
83 |
Correct |
728 ms |
314924 KB |
Output is correct |
84 |
Correct |
762 ms |
580912 KB |
Output is correct |
85 |
Correct |
1942 ms |
1397392 KB |
Output is correct |
86 |
Runtime error |
1223 ms |
2097152 KB |
Execution killed with signal 9 |
87 |
Halted |
0 ms |
0 KB |
- |