#include <bits/stdc++.h>
using namespace std;
#define int long long
char arr[2505];
int A,B,C;
int mem[2505][2505];
int cntocc(int a, int b, int st, int en){
int cur = b;
int ans = 1;
while (cur+(b-a)<=en){
bool can = true;
for (int x = 0; x<b-a; x++){
if (arr[cur+x]!=arr[a+x]){
can = false;
break;
}
}
if (can){
ans++;
cur += b-a;
}
else{
cur++;
}
}
return ans;
}
int func(int a, int b){
if (mem[a][b]!=-1) return mem[a][b];
if (a==b) return 0;
int ans = func(a+1,b)+A;
for (int x = 1; x<b-a; x++){
int 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);
}
//printf("func %lld %lld = %lld\n",a,b,ans);
return mem[a][b] = ans;
}
main(){
int n;
scanf("%lld",&n);
for (int x = 0; x<n; x++){
scanf(" %c",&arr[x]);
}
scanf("%lld%lld%lld",&A,&B,&C);
memset(mem,-1,sizeof(mem));
printf("%lld",func(0,n));
}
Compilation message
copypaste3.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
44 | main(){
| ^~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
copypaste3.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf(" %c",&arr[x]);
| ~~~~~^~~~~~~~~~~~~~~
copypaste3.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%lld%lld%lld",&A,&B,&C);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
49364 KB |
Output is correct |
2 |
Correct |
26 ms |
49364 KB |
Output is correct |
3 |
Correct |
20 ms |
49404 KB |
Output is correct |
4 |
Correct |
21 ms |
49468 KB |
Output is correct |
5 |
Correct |
23 ms |
49364 KB |
Output is correct |
6 |
Correct |
21 ms |
49324 KB |
Output is correct |
7 |
Correct |
21 ms |
49364 KB |
Output is correct |
8 |
Correct |
18 ms |
49364 KB |
Output is correct |
9 |
Correct |
19 ms |
49408 KB |
Output is correct |
10 |
Correct |
23 ms |
49376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
49380 KB |
Output is correct |
2 |
Correct |
20 ms |
49412 KB |
Output is correct |
3 |
Execution timed out |
3074 ms |
49492 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
49364 KB |
Output is correct |
2 |
Correct |
26 ms |
49364 KB |
Output is correct |
3 |
Correct |
20 ms |
49404 KB |
Output is correct |
4 |
Correct |
21 ms |
49468 KB |
Output is correct |
5 |
Correct |
23 ms |
49364 KB |
Output is correct |
6 |
Correct |
21 ms |
49324 KB |
Output is correct |
7 |
Correct |
21 ms |
49364 KB |
Output is correct |
8 |
Correct |
18 ms |
49364 KB |
Output is correct |
9 |
Correct |
19 ms |
49408 KB |
Output is correct |
10 |
Correct |
23 ms |
49376 KB |
Output is correct |
11 |
Correct |
18 ms |
49364 KB |
Output is correct |
12 |
Correct |
18 ms |
49312 KB |
Output is correct |
13 |
Correct |
19 ms |
49364 KB |
Output is correct |
14 |
Correct |
21 ms |
49388 KB |
Output is correct |
15 |
Correct |
19 ms |
49368 KB |
Output is correct |
16 |
Correct |
19 ms |
49364 KB |
Output is correct |
17 |
Correct |
20 ms |
49412 KB |
Output is correct |
18 |
Correct |
21 ms |
49368 KB |
Output is correct |
19 |
Correct |
25 ms |
49364 KB |
Output is correct |
20 |
Correct |
21 ms |
49408 KB |
Output is correct |
21 |
Correct |
21 ms |
49284 KB |
Output is correct |
22 |
Correct |
20 ms |
49368 KB |
Output is correct |
23 |
Correct |
22 ms |
49528 KB |
Output is correct |
24 |
Correct |
25 ms |
49332 KB |
Output is correct |
25 |
Correct |
24 ms |
49324 KB |
Output is correct |
26 |
Correct |
19 ms |
49304 KB |
Output is correct |
27 |
Correct |
19 ms |
49428 KB |
Output is correct |
28 |
Correct |
26 ms |
49384 KB |
Output is correct |
29 |
Correct |
21 ms |
49364 KB |
Output is correct |
30 |
Correct |
20 ms |
49364 KB |
Output is correct |
31 |
Correct |
23 ms |
49412 KB |
Output is correct |
32 |
Correct |
20 ms |
49352 KB |
Output is correct |
33 |
Correct |
20 ms |
49364 KB |
Output is correct |
34 |
Correct |
21 ms |
49364 KB |
Output is correct |
35 |
Correct |
20 ms |
49380 KB |
Output is correct |
36 |
Correct |
19 ms |
49316 KB |
Output is correct |
37 |
Correct |
18 ms |
49400 KB |
Output is correct |
38 |
Correct |
19 ms |
49308 KB |
Output is correct |
39 |
Correct |
19 ms |
49388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
49364 KB |
Output is correct |
2 |
Correct |
26 ms |
49364 KB |
Output is correct |
3 |
Correct |
20 ms |
49404 KB |
Output is correct |
4 |
Correct |
21 ms |
49468 KB |
Output is correct |
5 |
Correct |
23 ms |
49364 KB |
Output is correct |
6 |
Correct |
21 ms |
49324 KB |
Output is correct |
7 |
Correct |
21 ms |
49364 KB |
Output is correct |
8 |
Correct |
18 ms |
49364 KB |
Output is correct |
9 |
Correct |
19 ms |
49408 KB |
Output is correct |
10 |
Correct |
23 ms |
49376 KB |
Output is correct |
11 |
Correct |
18 ms |
49364 KB |
Output is correct |
12 |
Correct |
18 ms |
49312 KB |
Output is correct |
13 |
Correct |
19 ms |
49364 KB |
Output is correct |
14 |
Correct |
21 ms |
49388 KB |
Output is correct |
15 |
Correct |
19 ms |
49368 KB |
Output is correct |
16 |
Correct |
19 ms |
49364 KB |
Output is correct |
17 |
Correct |
20 ms |
49412 KB |
Output is correct |
18 |
Correct |
21 ms |
49368 KB |
Output is correct |
19 |
Correct |
25 ms |
49364 KB |
Output is correct |
20 |
Correct |
21 ms |
49408 KB |
Output is correct |
21 |
Correct |
21 ms |
49284 KB |
Output is correct |
22 |
Correct |
20 ms |
49368 KB |
Output is correct |
23 |
Correct |
22 ms |
49528 KB |
Output is correct |
24 |
Correct |
25 ms |
49332 KB |
Output is correct |
25 |
Correct |
24 ms |
49324 KB |
Output is correct |
26 |
Correct |
19 ms |
49304 KB |
Output is correct |
27 |
Correct |
19 ms |
49428 KB |
Output is correct |
28 |
Correct |
26 ms |
49384 KB |
Output is correct |
29 |
Correct |
21 ms |
49364 KB |
Output is correct |
30 |
Correct |
20 ms |
49364 KB |
Output is correct |
31 |
Correct |
23 ms |
49412 KB |
Output is correct |
32 |
Correct |
20 ms |
49352 KB |
Output is correct |
33 |
Correct |
20 ms |
49364 KB |
Output is correct |
34 |
Correct |
21 ms |
49364 KB |
Output is correct |
35 |
Correct |
20 ms |
49380 KB |
Output is correct |
36 |
Correct |
19 ms |
49316 KB |
Output is correct |
37 |
Correct |
18 ms |
49400 KB |
Output is correct |
38 |
Correct |
19 ms |
49308 KB |
Output is correct |
39 |
Correct |
19 ms |
49388 KB |
Output is correct |
40 |
Correct |
26 ms |
49412 KB |
Output is correct |
41 |
Correct |
79 ms |
49364 KB |
Output is correct |
42 |
Correct |
155 ms |
49412 KB |
Output is correct |
43 |
Correct |
129 ms |
49540 KB |
Output is correct |
44 |
Correct |
117 ms |
49484 KB |
Output is correct |
45 |
Correct |
94 ms |
49416 KB |
Output is correct |
46 |
Correct |
79 ms |
49416 KB |
Output is correct |
47 |
Correct |
85 ms |
49412 KB |
Output is correct |
48 |
Correct |
82 ms |
49408 KB |
Output is correct |
49 |
Correct |
91 ms |
49412 KB |
Output is correct |
50 |
Correct |
94 ms |
49364 KB |
Output is correct |
51 |
Correct |
104 ms |
49408 KB |
Output is correct |
52 |
Correct |
102 ms |
49412 KB |
Output is correct |
53 |
Correct |
102 ms |
49356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
49364 KB |
Output is correct |
2 |
Correct |
26 ms |
49364 KB |
Output is correct |
3 |
Correct |
20 ms |
49404 KB |
Output is correct |
4 |
Correct |
21 ms |
49468 KB |
Output is correct |
5 |
Correct |
23 ms |
49364 KB |
Output is correct |
6 |
Correct |
21 ms |
49324 KB |
Output is correct |
7 |
Correct |
21 ms |
49364 KB |
Output is correct |
8 |
Correct |
18 ms |
49364 KB |
Output is correct |
9 |
Correct |
19 ms |
49408 KB |
Output is correct |
10 |
Correct |
23 ms |
49376 KB |
Output is correct |
11 |
Correct |
18 ms |
49364 KB |
Output is correct |
12 |
Correct |
18 ms |
49312 KB |
Output is correct |
13 |
Correct |
19 ms |
49364 KB |
Output is correct |
14 |
Correct |
21 ms |
49388 KB |
Output is correct |
15 |
Correct |
19 ms |
49368 KB |
Output is correct |
16 |
Correct |
19 ms |
49364 KB |
Output is correct |
17 |
Correct |
20 ms |
49412 KB |
Output is correct |
18 |
Correct |
21 ms |
49368 KB |
Output is correct |
19 |
Correct |
25 ms |
49364 KB |
Output is correct |
20 |
Correct |
21 ms |
49408 KB |
Output is correct |
21 |
Correct |
21 ms |
49284 KB |
Output is correct |
22 |
Correct |
20 ms |
49368 KB |
Output is correct |
23 |
Correct |
22 ms |
49528 KB |
Output is correct |
24 |
Correct |
25 ms |
49332 KB |
Output is correct |
25 |
Correct |
24 ms |
49324 KB |
Output is correct |
26 |
Correct |
19 ms |
49304 KB |
Output is correct |
27 |
Correct |
19 ms |
49428 KB |
Output is correct |
28 |
Correct |
26 ms |
49384 KB |
Output is correct |
29 |
Correct |
21 ms |
49364 KB |
Output is correct |
30 |
Correct |
20 ms |
49364 KB |
Output is correct |
31 |
Correct |
23 ms |
49412 KB |
Output is correct |
32 |
Correct |
20 ms |
49352 KB |
Output is correct |
33 |
Correct |
20 ms |
49364 KB |
Output is correct |
34 |
Correct |
21 ms |
49364 KB |
Output is correct |
35 |
Correct |
20 ms |
49380 KB |
Output is correct |
36 |
Correct |
19 ms |
49316 KB |
Output is correct |
37 |
Correct |
18 ms |
49400 KB |
Output is correct |
38 |
Correct |
19 ms |
49308 KB |
Output is correct |
39 |
Correct |
19 ms |
49388 KB |
Output is correct |
40 |
Correct |
26 ms |
49412 KB |
Output is correct |
41 |
Correct |
79 ms |
49364 KB |
Output is correct |
42 |
Correct |
155 ms |
49412 KB |
Output is correct |
43 |
Correct |
129 ms |
49540 KB |
Output is correct |
44 |
Correct |
117 ms |
49484 KB |
Output is correct |
45 |
Correct |
94 ms |
49416 KB |
Output is correct |
46 |
Correct |
79 ms |
49416 KB |
Output is correct |
47 |
Correct |
85 ms |
49412 KB |
Output is correct |
48 |
Correct |
82 ms |
49408 KB |
Output is correct |
49 |
Correct |
91 ms |
49412 KB |
Output is correct |
50 |
Correct |
94 ms |
49364 KB |
Output is correct |
51 |
Correct |
104 ms |
49408 KB |
Output is correct |
52 |
Correct |
102 ms |
49412 KB |
Output is correct |
53 |
Correct |
102 ms |
49356 KB |
Output is correct |
54 |
Execution timed out |
3052 ms |
49364 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
49364 KB |
Output is correct |
2 |
Correct |
26 ms |
49364 KB |
Output is correct |
3 |
Correct |
20 ms |
49404 KB |
Output is correct |
4 |
Correct |
21 ms |
49468 KB |
Output is correct |
5 |
Correct |
23 ms |
49364 KB |
Output is correct |
6 |
Correct |
21 ms |
49324 KB |
Output is correct |
7 |
Correct |
21 ms |
49364 KB |
Output is correct |
8 |
Correct |
18 ms |
49364 KB |
Output is correct |
9 |
Correct |
19 ms |
49408 KB |
Output is correct |
10 |
Correct |
23 ms |
49376 KB |
Output is correct |
11 |
Correct |
24 ms |
49380 KB |
Output is correct |
12 |
Correct |
20 ms |
49412 KB |
Output is correct |
13 |
Execution timed out |
3074 ms |
49492 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |