답안 #890247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890247 2023-12-20T19:08:38 Z amirhoseinfar1385 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
227 ms 74380 KB
#include<bits/stdc++.h>
using namespace std;
const short maxn=2500+10;
short lcp[maxn][maxn],nxt[maxn][maxn],n;
long long dp[maxn][maxn],a,b,c,inf=1e15;
string s;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>s;
	cin>>a>>b>>c;
	for(short i=n-1;i>=0;i--){
		for(short j=i+1;j<n;j++){
			if(s[i]==s[j]){
				lcp[i][j]=lcp[i+1][j+1]+1;
			}
		}
	}
	for(short i=0;i<maxn;i++){
		for(short j=0;j<maxn;j++){
			nxt[i][j]=n+3;
		}
	}
	for(short i=0;i<n;i++){
		for(short j=n-1;j>i;j--){
			nxt[i][lcp[i][j]>(j-i)?(j-i):lcp[i][j]]=j;
		}
		for(short j=n;j>=0;j--){
			nxt[i][j]=min(nxt[i][j],nxt[i][j+1]);
		}
	}
	for(short i=0;i<maxn;i++){
		for(short j=0;j<maxn;j++){
			dp[i][j]=inf;
		}
	}
	for(short i=n-1;i>=0;i--){
		dp[i][i]=a;
		for(short j=i+1;j<n;j++){
			dp[i][j]=min(dp[i][j],min(dp[i+1][j],dp[i][j-1])+a);
		}
		for(short j=1;j<n;j++){
			dp[i][j+i-1]=min(dp[i][j+i-1],min(dp[i+1][j+i-1],dp[i][j+i-2])+a);
			short ted=2;
			long long z=dp[i][j+i-1];
			for(long long h=nxt[i][j];h!=n+3;h=nxt[h][j]){
			//	cout<<i<<" "<<h<<" "<<j<<" "<<ted<<" "<<z<<" "<<endl;
				dp[i][h+j-1]=min(dp[i][h+j-1],z+c*ted+b+a*(h+j-i-(ted*j)));
				ted++;
			}
		}
		for(long long j=i+1;j<n;j++){
			dp[i][j]=min(dp[i][j],min(dp[i+1][j],dp[i][j-1])+a);
		}
	}
	cout<<dp[0][n-1]<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 62040 KB Output is correct
2 Correct 11 ms 62044 KB Output is correct
3 Correct 11 ms 62044 KB Output is correct
4 Correct 14 ms 62044 KB Output is correct
5 Correct 11 ms 62044 KB Output is correct
6 Correct 13 ms 62044 KB Output is correct
7 Correct 10 ms 62168 KB Output is correct
8 Correct 11 ms 62044 KB Output is correct
9 Correct 11 ms 62040 KB Output is correct
10 Correct 11 ms 62040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 62044 KB Output is correct
2 Correct 11 ms 62044 KB Output is correct
3 Correct 117 ms 70740 KB Output is correct
4 Correct 122 ms 71612 KB Output is correct
5 Correct 160 ms 72316 KB Output is correct
6 Correct 175 ms 73044 KB Output is correct
7 Correct 208 ms 74068 KB Output is correct
8 Correct 210 ms 74160 KB Output is correct
9 Correct 227 ms 74372 KB Output is correct
10 Correct 10 ms 62044 KB Output is correct
11 Correct 11 ms 61932 KB Output is correct
12 Correct 11 ms 62040 KB Output is correct
13 Correct 11 ms 62044 KB Output is correct
14 Correct 11 ms 62096 KB Output is correct
15 Correct 11 ms 62044 KB Output is correct
16 Correct 10 ms 62168 KB Output is correct
17 Correct 11 ms 62044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 62040 KB Output is correct
2 Correct 11 ms 62044 KB Output is correct
3 Correct 11 ms 62044 KB Output is correct
4 Correct 14 ms 62044 KB Output is correct
5 Correct 11 ms 62044 KB Output is correct
6 Correct 13 ms 62044 KB Output is correct
7 Correct 10 ms 62168 KB Output is correct
8 Correct 11 ms 62044 KB Output is correct
9 Correct 11 ms 62040 KB Output is correct
10 Correct 11 ms 62040 KB Output is correct
11 Correct 11 ms 62044 KB Output is correct
12 Correct 11 ms 62044 KB Output is correct
13 Correct 11 ms 62044 KB Output is correct
14 Correct 11 ms 62124 KB Output is correct
15 Correct 11 ms 62044 KB Output is correct
16 Correct 11 ms 62044 KB Output is correct
17 Correct 11 ms 62044 KB Output is correct
18 Correct 10 ms 62044 KB Output is correct
19 Correct 12 ms 62044 KB Output is correct
20 Correct 11 ms 61928 KB Output is correct
21 Correct 11 ms 62236 KB Output is correct
22 Correct 10 ms 62040 KB Output is correct
23 Correct 11 ms 62040 KB Output is correct
24 Correct 11 ms 62044 KB Output is correct
25 Correct 12 ms 62044 KB Output is correct
26 Correct 11 ms 62208 KB Output is correct
27 Correct 11 ms 62044 KB Output is correct
28 Correct 11 ms 62044 KB Output is correct
29 Correct 10 ms 62044 KB Output is correct
30 Correct 11 ms 62180 KB Output is correct
31 Correct 11 ms 62044 KB Output is correct
32 Correct 11 ms 62044 KB Output is correct
33 Correct 11 ms 62116 KB Output is correct
34 Correct 10 ms 62156 KB Output is correct
35 Correct 12 ms 62212 KB Output is correct
36 Correct 11 ms 62044 KB Output is correct
37 Correct 11 ms 61944 KB Output is correct
38 Correct 11 ms 62044 KB Output is correct
39 Correct 11 ms 62040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 62040 KB Output is correct
2 Correct 11 ms 62044 KB Output is correct
3 Correct 11 ms 62044 KB Output is correct
4 Correct 14 ms 62044 KB Output is correct
5 Correct 11 ms 62044 KB Output is correct
6 Correct 13 ms 62044 KB Output is correct
7 Correct 10 ms 62168 KB Output is correct
8 Correct 11 ms 62044 KB Output is correct
9 Correct 11 ms 62040 KB Output is correct
10 Correct 11 ms 62040 KB Output is correct
11 Correct 11 ms 62044 KB Output is correct
12 Correct 11 ms 62044 KB Output is correct
13 Correct 11 ms 62044 KB Output is correct
14 Correct 11 ms 62124 KB Output is correct
15 Correct 11 ms 62044 KB Output is correct
16 Correct 11 ms 62044 KB Output is correct
17 Correct 11 ms 62044 KB Output is correct
18 Correct 10 ms 62044 KB Output is correct
19 Correct 12 ms 62044 KB Output is correct
20 Correct 11 ms 61928 KB Output is correct
21 Correct 11 ms 62236 KB Output is correct
22 Correct 10 ms 62040 KB Output is correct
23 Correct 11 ms 62040 KB Output is correct
24 Correct 11 ms 62044 KB Output is correct
25 Correct 12 ms 62044 KB Output is correct
26 Correct 11 ms 62208 KB Output is correct
27 Correct 11 ms 62044 KB Output is correct
28 Correct 11 ms 62044 KB Output is correct
29 Correct 10 ms 62044 KB Output is correct
30 Correct 11 ms 62180 KB Output is correct
31 Correct 11 ms 62044 KB Output is correct
32 Correct 11 ms 62044 KB Output is correct
33 Correct 11 ms 62116 KB Output is correct
34 Correct 10 ms 62156 KB Output is correct
35 Correct 12 ms 62212 KB Output is correct
36 Correct 11 ms 62044 KB Output is correct
37 Correct 11 ms 61944 KB Output is correct
38 Correct 11 ms 62044 KB Output is correct
39 Correct 11 ms 62040 KB Output is correct
40 Correct 11 ms 62300 KB Output is correct
41 Correct 15 ms 62812 KB Output is correct
42 Correct 11 ms 62812 KB Output is correct
43 Correct 12 ms 62896 KB Output is correct
44 Correct 11 ms 62812 KB Output is correct
45 Correct 11 ms 62888 KB Output is correct
46 Correct 12 ms 62828 KB Output is correct
47 Correct 13 ms 62808 KB Output is correct
48 Correct 11 ms 62768 KB Output is correct
49 Correct 12 ms 62868 KB Output is correct
50 Correct 11 ms 62812 KB Output is correct
51 Correct 11 ms 62812 KB Output is correct
52 Correct 11 ms 63064 KB Output is correct
53 Correct 12 ms 62812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 62040 KB Output is correct
2 Correct 11 ms 62044 KB Output is correct
3 Correct 11 ms 62044 KB Output is correct
4 Correct 14 ms 62044 KB Output is correct
5 Correct 11 ms 62044 KB Output is correct
6 Correct 13 ms 62044 KB Output is correct
7 Correct 10 ms 62168 KB Output is correct
8 Correct 11 ms 62044 KB Output is correct
9 Correct 11 ms 62040 KB Output is correct
10 Correct 11 ms 62040 KB Output is correct
11 Correct 11 ms 62044 KB Output is correct
12 Correct 11 ms 62044 KB Output is correct
13 Correct 11 ms 62044 KB Output is correct
14 Correct 11 ms 62124 KB Output is correct
15 Correct 11 ms 62044 KB Output is correct
16 Correct 11 ms 62044 KB Output is correct
17 Correct 11 ms 62044 KB Output is correct
18 Correct 10 ms 62044 KB Output is correct
19 Correct 12 ms 62044 KB Output is correct
20 Correct 11 ms 61928 KB Output is correct
21 Correct 11 ms 62236 KB Output is correct
22 Correct 10 ms 62040 KB Output is correct
23 Correct 11 ms 62040 KB Output is correct
24 Correct 11 ms 62044 KB Output is correct
25 Correct 12 ms 62044 KB Output is correct
26 Correct 11 ms 62208 KB Output is correct
27 Correct 11 ms 62044 KB Output is correct
28 Correct 11 ms 62044 KB Output is correct
29 Correct 10 ms 62044 KB Output is correct
30 Correct 11 ms 62180 KB Output is correct
31 Correct 11 ms 62044 KB Output is correct
32 Correct 11 ms 62044 KB Output is correct
33 Correct 11 ms 62116 KB Output is correct
34 Correct 10 ms 62156 KB Output is correct
35 Correct 12 ms 62212 KB Output is correct
36 Correct 11 ms 62044 KB Output is correct
37 Correct 11 ms 61944 KB Output is correct
38 Correct 11 ms 62044 KB Output is correct
39 Correct 11 ms 62040 KB Output is correct
40 Correct 11 ms 62300 KB Output is correct
41 Correct 15 ms 62812 KB Output is correct
42 Correct 11 ms 62812 KB Output is correct
43 Correct 12 ms 62896 KB Output is correct
44 Correct 11 ms 62812 KB Output is correct
45 Correct 11 ms 62888 KB Output is correct
46 Correct 12 ms 62828 KB Output is correct
47 Correct 13 ms 62808 KB Output is correct
48 Correct 11 ms 62768 KB Output is correct
49 Correct 12 ms 62868 KB Output is correct
50 Correct 11 ms 62812 KB Output is correct
51 Correct 11 ms 62812 KB Output is correct
52 Correct 11 ms 63064 KB Output is correct
53 Correct 12 ms 62812 KB Output is correct
54 Correct 14 ms 64088 KB Output is correct
55 Correct 35 ms 66824 KB Output is correct
56 Correct 25 ms 66652 KB Output is correct
57 Correct 26 ms 66652 KB Output is correct
58 Correct 23 ms 66652 KB Output is correct
59 Correct 23 ms 66848 KB Output is correct
60 Correct 26 ms 66772 KB Output is correct
61 Correct 24 ms 66652 KB Output is correct
62 Correct 32 ms 66648 KB Output is correct
63 Correct 23 ms 66752 KB Output is correct
64 Correct 24 ms 66728 KB Output is correct
65 Correct 26 ms 66648 KB Output is correct
66 Correct 26 ms 66848 KB Output is correct
67 Correct 23 ms 66768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 62040 KB Output is correct
2 Correct 11 ms 62044 KB Output is correct
3 Correct 11 ms 62044 KB Output is correct
4 Correct 14 ms 62044 KB Output is correct
5 Correct 11 ms 62044 KB Output is correct
6 Correct 13 ms 62044 KB Output is correct
7 Correct 10 ms 62168 KB Output is correct
8 Correct 11 ms 62044 KB Output is correct
9 Correct 11 ms 62040 KB Output is correct
10 Correct 11 ms 62040 KB Output is correct
11 Correct 11 ms 62044 KB Output is correct
12 Correct 11 ms 62044 KB Output is correct
13 Correct 117 ms 70740 KB Output is correct
14 Correct 122 ms 71612 KB Output is correct
15 Correct 160 ms 72316 KB Output is correct
16 Correct 175 ms 73044 KB Output is correct
17 Correct 208 ms 74068 KB Output is correct
18 Correct 210 ms 74160 KB Output is correct
19 Correct 227 ms 74372 KB Output is correct
20 Correct 10 ms 62044 KB Output is correct
21 Correct 11 ms 61932 KB Output is correct
22 Correct 11 ms 62040 KB Output is correct
23 Correct 11 ms 62044 KB Output is correct
24 Correct 11 ms 62096 KB Output is correct
25 Correct 11 ms 62044 KB Output is correct
26 Correct 10 ms 62168 KB Output is correct
27 Correct 11 ms 62044 KB Output is correct
28 Correct 11 ms 62044 KB Output is correct
29 Correct 11 ms 62044 KB Output is correct
30 Correct 11 ms 62044 KB Output is correct
31 Correct 11 ms 62124 KB Output is correct
32 Correct 11 ms 62044 KB Output is correct
33 Correct 11 ms 62044 KB Output is correct
34 Correct 11 ms 62044 KB Output is correct
35 Correct 10 ms 62044 KB Output is correct
36 Correct 12 ms 62044 KB Output is correct
37 Correct 11 ms 61928 KB Output is correct
38 Correct 11 ms 62236 KB Output is correct
39 Correct 10 ms 62040 KB Output is correct
40 Correct 11 ms 62040 KB Output is correct
41 Correct 11 ms 62044 KB Output is correct
42 Correct 12 ms 62044 KB Output is correct
43 Correct 11 ms 62208 KB Output is correct
44 Correct 11 ms 62044 KB Output is correct
45 Correct 11 ms 62044 KB Output is correct
46 Correct 10 ms 62044 KB Output is correct
47 Correct 11 ms 62180 KB Output is correct
48 Correct 11 ms 62044 KB Output is correct
49 Correct 11 ms 62044 KB Output is correct
50 Correct 11 ms 62116 KB Output is correct
51 Correct 10 ms 62156 KB Output is correct
52 Correct 12 ms 62212 KB Output is correct
53 Correct 11 ms 62044 KB Output is correct
54 Correct 11 ms 61944 KB Output is correct
55 Correct 11 ms 62044 KB Output is correct
56 Correct 11 ms 62040 KB Output is correct
57 Correct 11 ms 62300 KB Output is correct
58 Correct 15 ms 62812 KB Output is correct
59 Correct 11 ms 62812 KB Output is correct
60 Correct 12 ms 62896 KB Output is correct
61 Correct 11 ms 62812 KB Output is correct
62 Correct 11 ms 62888 KB Output is correct
63 Correct 12 ms 62828 KB Output is correct
64 Correct 13 ms 62808 KB Output is correct
65 Correct 11 ms 62768 KB Output is correct
66 Correct 12 ms 62868 KB Output is correct
67 Correct 11 ms 62812 KB Output is correct
68 Correct 11 ms 62812 KB Output is correct
69 Correct 11 ms 63064 KB Output is correct
70 Correct 12 ms 62812 KB Output is correct
71 Correct 14 ms 64088 KB Output is correct
72 Correct 35 ms 66824 KB Output is correct
73 Correct 25 ms 66652 KB Output is correct
74 Correct 26 ms 66652 KB Output is correct
75 Correct 23 ms 66652 KB Output is correct
76 Correct 23 ms 66848 KB Output is correct
77 Correct 26 ms 66772 KB Output is correct
78 Correct 24 ms 66652 KB Output is correct
79 Correct 32 ms 66648 KB Output is correct
80 Correct 23 ms 66752 KB Output is correct
81 Correct 24 ms 66728 KB Output is correct
82 Correct 26 ms 66648 KB Output is correct
83 Correct 26 ms 66848 KB Output is correct
84 Correct 23 ms 66768 KB Output is correct
85 Correct 45 ms 69468 KB Output is correct
86 Correct 99 ms 74064 KB Output is correct
87 Correct 91 ms 74064 KB Output is correct
88 Correct 88 ms 74136 KB Output is correct
89 Correct 84 ms 74104 KB Output is correct
90 Correct 82 ms 73768 KB Output is correct
91 Correct 102 ms 74020 KB Output is correct
92 Correct 127 ms 74120 KB Output is correct
93 Correct 87 ms 74060 KB Output is correct
94 Correct 87 ms 74040 KB Output is correct
95 Correct 117 ms 74136 KB Output is correct
96 Correct 118 ms 74380 KB Output is correct
97 Correct 87 ms 73988 KB Output is correct