Submission #887540

# Submission time Handle Problem Language Result Execution time Memory
887540 2023-12-14T17:40:16 Z Ahmed57 Copy and Paste 3 (JOI22_copypaste3) C++17
30 / 100
978 ms 133152 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
long long n,a,b,c;string s;
int lcp[201][201];
long long dp[201][201][201];
long long solve(int i,int l,int r){
	if(l==0&&r==n){
		return 0;
	}
	if(i==n){
		return 1e18;
	}
	if(dp[i][l][r]!=-1)return dp[i][l][r];
	long long cost = 0 , j = 0;
	long long c1 = solve(i+1,l,r);
	for(j = i;j<n;){
        int lol = (r-l<=lcp[j][l]?r-l:0);
        if(lol==0){
        	cost+=a;
        	if(j+1-i>r-l)c1 = min(c1,solve(0,i,j+1)+cost+b);
        	j++;
        	continue;
        }
        for(long long e = j+1;e<min(n+1,lol+j);e++){
            if(e-i>r-l)c1 = min(c1,solve(0,i,e)+cost+(e-j)*a+b);
        }
        cost+=min((r-l)*a,c);
        if(min(n,lol+j)-i>r-l)c1 = min(c1,solve(0,i,min(n,lol+j))+cost+b);
        j+=r-l;
	}
	return dp[i][l][r] = c1;
}
long long dp2[2501][2501];
long long solve2(int i,int cu){
	if(i==n){
		return 0;
	}
	if(dp2[i][cu]!=-1)return dp2[i][cu];
	long long c1 = solve2(i+1,cu)+a;
	if(cu&&i+cu<=n)c1 = min(c1,solve2(i+cu,cu)+c);
	if(i>cu)c1 = min(c1,solve2(0,i)+b);
	return dp2[i][cu] = c1;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>s>>a>>b>>c;
	memset(dp,-1,sizeof dp);
	bool bb = 1;
	for(int i = 1;i<n;i++){
		if(s[i]!=s[i-1]){
			bb = 0;
		}
	}
	if(bb){
		memset(dp2,-1,sizeof dp2);
		cout<<solve2(0,0)<<endl;
		return 0;
	}
	for(int i = 0;i<n;i++){
		for(int j = 0;j<n;j++){
			for(int k = 0;k<min(n-i,n-j);k++){
				if(s[i+k]==s[j+k]){
					lcp[i][j]++;
				}else break;
			}
		}
	}
	cout<<solve(0,0,0)-b<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 112996 KB Output is correct
2 Correct 8 ms 65536 KB Output is correct
3 Correct 10 ms 65372 KB Output is correct
4 Correct 15 ms 112732 KB Output is correct
5 Correct 8 ms 65372 KB Output is correct
6 Correct 8 ms 65372 KB Output is correct
7 Correct 8 ms 65568 KB Output is correct
8 Correct 13 ms 112732 KB Output is correct
9 Correct 14 ms 112732 KB Output is correct
10 Correct 13 ms 112888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 112988 KB Output is correct
2 Correct 14 ms 112988 KB Output is correct
3 Correct 58 ms 112988 KB Output is correct
4 Correct 79 ms 112988 KB Output is correct
5 Correct 82 ms 112984 KB Output is correct
6 Correct 83 ms 113188 KB Output is correct
7 Correct 94 ms 113208 KB Output is correct
8 Correct 108 ms 113204 KB Output is correct
9 Correct 99 ms 112988 KB Output is correct
10 Correct 14 ms 112856 KB Output is correct
11 Correct 14 ms 112988 KB Output is correct
12 Correct 15 ms 112988 KB Output is correct
13 Correct 14 ms 112988 KB Output is correct
14 Correct 14 ms 112988 KB Output is correct
15 Correct 14 ms 112924 KB Output is correct
16 Correct 13 ms 112988 KB Output is correct
17 Correct 14 ms 112956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 112996 KB Output is correct
2 Correct 8 ms 65536 KB Output is correct
3 Correct 10 ms 65372 KB Output is correct
4 Correct 15 ms 112732 KB Output is correct
5 Correct 8 ms 65372 KB Output is correct
6 Correct 8 ms 65372 KB Output is correct
7 Correct 8 ms 65568 KB Output is correct
8 Correct 13 ms 112732 KB Output is correct
9 Correct 14 ms 112732 KB Output is correct
10 Correct 13 ms 112888 KB Output is correct
11 Correct 8 ms 65824 KB Output is correct
12 Correct 14 ms 112728 KB Output is correct
13 Correct 8 ms 65628 KB Output is correct
14 Correct 8 ms 65628 KB Output is correct
15 Correct 8 ms 65628 KB Output is correct
16 Correct 8 ms 65540 KB Output is correct
17 Correct 9 ms 65372 KB Output is correct
18 Correct 15 ms 112988 KB Output is correct
19 Correct 9 ms 65880 KB Output is correct
20 Correct 8 ms 65368 KB Output is correct
21 Correct 13 ms 112984 KB Output is correct
22 Correct 10 ms 65628 KB Output is correct
23 Correct 9 ms 65576 KB Output is correct
24 Correct 9 ms 65628 KB Output is correct
25 Correct 9 ms 65628 KB Output is correct
26 Correct 9 ms 65628 KB Output is correct
27 Correct 9 ms 65604 KB Output is correct
28 Correct 9 ms 65628 KB Output is correct
29 Correct 9 ms 65628 KB Output is correct
30 Correct 9 ms 65628 KB Output is correct
31 Correct 9 ms 65540 KB Output is correct
32 Correct 9 ms 65628 KB Output is correct
33 Correct 9 ms 65628 KB Output is correct
34 Correct 14 ms 112732 KB Output is correct
35 Correct 14 ms 112732 KB Output is correct
36 Correct 14 ms 112952 KB Output is correct
37 Correct 14 ms 112988 KB Output is correct
38 Correct 15 ms 112988 KB Output is correct
39 Correct 14 ms 112940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 112996 KB Output is correct
2 Correct 8 ms 65536 KB Output is correct
3 Correct 10 ms 65372 KB Output is correct
4 Correct 15 ms 112732 KB Output is correct
5 Correct 8 ms 65372 KB Output is correct
6 Correct 8 ms 65372 KB Output is correct
7 Correct 8 ms 65568 KB Output is correct
8 Correct 13 ms 112732 KB Output is correct
9 Correct 14 ms 112732 KB Output is correct
10 Correct 13 ms 112888 KB Output is correct
11 Correct 8 ms 65824 KB Output is correct
12 Correct 14 ms 112728 KB Output is correct
13 Correct 8 ms 65628 KB Output is correct
14 Correct 8 ms 65628 KB Output is correct
15 Correct 8 ms 65628 KB Output is correct
16 Correct 8 ms 65540 KB Output is correct
17 Correct 9 ms 65372 KB Output is correct
18 Correct 15 ms 112988 KB Output is correct
19 Correct 9 ms 65880 KB Output is correct
20 Correct 8 ms 65368 KB Output is correct
21 Correct 13 ms 112984 KB Output is correct
22 Correct 10 ms 65628 KB Output is correct
23 Correct 9 ms 65576 KB Output is correct
24 Correct 9 ms 65628 KB Output is correct
25 Correct 9 ms 65628 KB Output is correct
26 Correct 9 ms 65628 KB Output is correct
27 Correct 9 ms 65604 KB Output is correct
28 Correct 9 ms 65628 KB Output is correct
29 Correct 9 ms 65628 KB Output is correct
30 Correct 9 ms 65628 KB Output is correct
31 Correct 9 ms 65540 KB Output is correct
32 Correct 9 ms 65628 KB Output is correct
33 Correct 9 ms 65628 KB Output is correct
34 Correct 14 ms 112732 KB Output is correct
35 Correct 14 ms 112732 KB Output is correct
36 Correct 14 ms 112952 KB Output is correct
37 Correct 14 ms 112988 KB Output is correct
38 Correct 15 ms 112988 KB Output is correct
39 Correct 14 ms 112940 KB Output is correct
40 Correct 44 ms 66140 KB Output is correct
41 Correct 14 ms 112988 KB Output is correct
42 Correct 978 ms 68444 KB Output is correct
43 Correct 946 ms 68440 KB Output is correct
44 Correct 952 ms 68440 KB Output is correct
45 Correct 952 ms 68444 KB Output is correct
46 Correct 949 ms 68444 KB Output is correct
47 Correct 879 ms 68692 KB Output is correct
48 Correct 916 ms 68444 KB Output is correct
49 Correct 914 ms 68444 KB Output is correct
50 Correct 916 ms 68444 KB Output is correct
51 Correct 898 ms 68444 KB Output is correct
52 Correct 918 ms 68444 KB Output is correct
53 Correct 927 ms 68440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 112996 KB Output is correct
2 Correct 8 ms 65536 KB Output is correct
3 Correct 10 ms 65372 KB Output is correct
4 Correct 15 ms 112732 KB Output is correct
5 Correct 8 ms 65372 KB Output is correct
6 Correct 8 ms 65372 KB Output is correct
7 Correct 8 ms 65568 KB Output is correct
8 Correct 13 ms 112732 KB Output is correct
9 Correct 14 ms 112732 KB Output is correct
10 Correct 13 ms 112888 KB Output is correct
11 Correct 8 ms 65824 KB Output is correct
12 Correct 14 ms 112728 KB Output is correct
13 Correct 8 ms 65628 KB Output is correct
14 Correct 8 ms 65628 KB Output is correct
15 Correct 8 ms 65628 KB Output is correct
16 Correct 8 ms 65540 KB Output is correct
17 Correct 9 ms 65372 KB Output is correct
18 Correct 15 ms 112988 KB Output is correct
19 Correct 9 ms 65880 KB Output is correct
20 Correct 8 ms 65368 KB Output is correct
21 Correct 13 ms 112984 KB Output is correct
22 Correct 10 ms 65628 KB Output is correct
23 Correct 9 ms 65576 KB Output is correct
24 Correct 9 ms 65628 KB Output is correct
25 Correct 9 ms 65628 KB Output is correct
26 Correct 9 ms 65628 KB Output is correct
27 Correct 9 ms 65604 KB Output is correct
28 Correct 9 ms 65628 KB Output is correct
29 Correct 9 ms 65628 KB Output is correct
30 Correct 9 ms 65628 KB Output is correct
31 Correct 9 ms 65540 KB Output is correct
32 Correct 9 ms 65628 KB Output is correct
33 Correct 9 ms 65628 KB Output is correct
34 Correct 14 ms 112732 KB Output is correct
35 Correct 14 ms 112732 KB Output is correct
36 Correct 14 ms 112952 KB Output is correct
37 Correct 14 ms 112988 KB Output is correct
38 Correct 15 ms 112988 KB Output is correct
39 Correct 14 ms 112940 KB Output is correct
40 Correct 44 ms 66140 KB Output is correct
41 Correct 14 ms 112988 KB Output is correct
42 Correct 978 ms 68444 KB Output is correct
43 Correct 946 ms 68440 KB Output is correct
44 Correct 952 ms 68440 KB Output is correct
45 Correct 952 ms 68444 KB Output is correct
46 Correct 949 ms 68444 KB Output is correct
47 Correct 879 ms 68692 KB Output is correct
48 Correct 916 ms 68444 KB Output is correct
49 Correct 914 ms 68444 KB Output is correct
50 Correct 916 ms 68444 KB Output is correct
51 Correct 898 ms 68444 KB Output is correct
52 Correct 918 ms 68444 KB Output is correct
53 Correct 927 ms 68440 KB Output is correct
54 Runtime error 60 ms 133152 KB Execution killed with signal 11
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 112996 KB Output is correct
2 Correct 8 ms 65536 KB Output is correct
3 Correct 10 ms 65372 KB Output is correct
4 Correct 15 ms 112732 KB Output is correct
5 Correct 8 ms 65372 KB Output is correct
6 Correct 8 ms 65372 KB Output is correct
7 Correct 8 ms 65568 KB Output is correct
8 Correct 13 ms 112732 KB Output is correct
9 Correct 14 ms 112732 KB Output is correct
10 Correct 13 ms 112888 KB Output is correct
11 Correct 14 ms 112988 KB Output is correct
12 Correct 14 ms 112988 KB Output is correct
13 Correct 58 ms 112988 KB Output is correct
14 Correct 79 ms 112988 KB Output is correct
15 Correct 82 ms 112984 KB Output is correct
16 Correct 83 ms 113188 KB Output is correct
17 Correct 94 ms 113208 KB Output is correct
18 Correct 108 ms 113204 KB Output is correct
19 Correct 99 ms 112988 KB Output is correct
20 Correct 14 ms 112856 KB Output is correct
21 Correct 14 ms 112988 KB Output is correct
22 Correct 15 ms 112988 KB Output is correct
23 Correct 14 ms 112988 KB Output is correct
24 Correct 14 ms 112988 KB Output is correct
25 Correct 14 ms 112924 KB Output is correct
26 Correct 13 ms 112988 KB Output is correct
27 Correct 14 ms 112956 KB Output is correct
28 Correct 8 ms 65824 KB Output is correct
29 Correct 14 ms 112728 KB Output is correct
30 Correct 8 ms 65628 KB Output is correct
31 Correct 8 ms 65628 KB Output is correct
32 Correct 8 ms 65628 KB Output is correct
33 Correct 8 ms 65540 KB Output is correct
34 Correct 9 ms 65372 KB Output is correct
35 Correct 15 ms 112988 KB Output is correct
36 Correct 9 ms 65880 KB Output is correct
37 Correct 8 ms 65368 KB Output is correct
38 Correct 13 ms 112984 KB Output is correct
39 Correct 10 ms 65628 KB Output is correct
40 Correct 9 ms 65576 KB Output is correct
41 Correct 9 ms 65628 KB Output is correct
42 Correct 9 ms 65628 KB Output is correct
43 Correct 9 ms 65628 KB Output is correct
44 Correct 9 ms 65604 KB Output is correct
45 Correct 9 ms 65628 KB Output is correct
46 Correct 9 ms 65628 KB Output is correct
47 Correct 9 ms 65628 KB Output is correct
48 Correct 9 ms 65540 KB Output is correct
49 Correct 9 ms 65628 KB Output is correct
50 Correct 9 ms 65628 KB Output is correct
51 Correct 14 ms 112732 KB Output is correct
52 Correct 14 ms 112732 KB Output is correct
53 Correct 14 ms 112952 KB Output is correct
54 Correct 14 ms 112988 KB Output is correct
55 Correct 15 ms 112988 KB Output is correct
56 Correct 14 ms 112940 KB Output is correct
57 Correct 44 ms 66140 KB Output is correct
58 Correct 14 ms 112988 KB Output is correct
59 Correct 978 ms 68444 KB Output is correct
60 Correct 946 ms 68440 KB Output is correct
61 Correct 952 ms 68440 KB Output is correct
62 Correct 952 ms 68444 KB Output is correct
63 Correct 949 ms 68444 KB Output is correct
64 Correct 879 ms 68692 KB Output is correct
65 Correct 916 ms 68444 KB Output is correct
66 Correct 914 ms 68444 KB Output is correct
67 Correct 916 ms 68444 KB Output is correct
68 Correct 898 ms 68444 KB Output is correct
69 Correct 918 ms 68444 KB Output is correct
70 Correct 927 ms 68440 KB Output is correct
71 Runtime error 60 ms 133152 KB Execution killed with signal 11
72 Halted 0 ms 0 KB -