답안 #551903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551903 2022-04-21T20:57:27 Z Antekb Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
678 ms 34008 KB
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
using ll = long long;
const int N=2505;
ll dp[N][N];
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int A, B, C;
	cin>>A>>B>>C;
	for(int l=1; l<=n; l++){
		for(int i=0; i<=n-l; i++){
			dp[i][i+l-1]=max({dp[i][i+l-1], dp[i][i+l-2], dp[i+1][i+l-1]});
		}
		ll pot=1;
		int bas=124338541;
		ll hasz=0;
		for(int i=0; i<l; i++){
			pot*=bas;	
		}
		vector<pair<ll, int> > V;
		for(int i=0; i<n; i++){
			hasz*=bas;
			hasz+=s[i];
			if(i>=l)hasz-=pot*ll(s[i-l]);
			if(i>=l-1)V.push_back({hasz, i});
		}
		vector<int> par(n, -1);
		sort(V.begin(), V.end());
		for(int i=0; i<=n-l; i++){
			//cout<<V[i].st<<","<<V[i].nd<<" ";
			int t=upper_bound(V.begin(), V.end(), make_pair(V[i].st, V[i].nd-l))-V.begin();
			t--;
			if(t>=0 && V[t].st==V[i].st)par[V[i].nd]=V[t].nd;
		}
		//cout<<"\n";
		for(int i=0; i<n; i++){
			//cout<<i<<" "<<par[i]<<"\n";
			int j=2, p=par[i];
			while(p!=-1){
				//if(l==3 && i==7 && p==4)cout<<"a"<<" "<<(j-1)*l*1ll*A<<" "<<dp[p-l+1][p]<<" "<<B+j*1ll*C<<"\n";
				dp[p-l+1][i]=max(dp[p-l+1][i], (j-1)*l*1ll*A+dp[p-l+1][p]-B-j*1ll*C);
				p=par[p];
				j++;
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=i; j<n; j++){
			//cout<<A*(j-i+1)-dp[i][j]<<" \n"[j==n-1];
		}
	}
	cout<<A*1ll*n-dp[0][n-1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 389 ms 20760 KB Output is correct
4 Correct 419 ms 23572 KB Output is correct
5 Correct 450 ms 26784 KB Output is correct
6 Correct 594 ms 30172 KB Output is correct
7 Correct 678 ms 33880 KB Output is correct
8 Correct 646 ms 33884 KB Output is correct
9 Correct 618 ms 33988 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 436 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 436 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 304 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 436 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 436 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 304 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 2 ms 1236 KB Output is correct
42 Correct 3 ms 1264 KB Output is correct
43 Correct 3 ms 1236 KB Output is correct
44 Correct 3 ms 1236 KB Output is correct
45 Correct 2 ms 1236 KB Output is correct
46 Correct 3 ms 1236 KB Output is correct
47 Correct 3 ms 1236 KB Output is correct
48 Correct 3 ms 1236 KB Output is correct
49 Correct 4 ms 1256 KB Output is correct
50 Correct 4 ms 1260 KB Output is correct
51 Correct 4 ms 1236 KB Output is correct
52 Correct 3 ms 1236 KB Output is correct
53 Correct 3 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 436 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 436 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 304 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 2 ms 1236 KB Output is correct
42 Correct 3 ms 1264 KB Output is correct
43 Correct 3 ms 1236 KB Output is correct
44 Correct 3 ms 1236 KB Output is correct
45 Correct 2 ms 1236 KB Output is correct
46 Correct 3 ms 1236 KB Output is correct
47 Correct 3 ms 1236 KB Output is correct
48 Correct 3 ms 1236 KB Output is correct
49 Correct 4 ms 1256 KB Output is correct
50 Correct 4 ms 1260 KB Output is correct
51 Correct 4 ms 1236 KB Output is correct
52 Correct 3 ms 1236 KB Output is correct
53 Correct 3 ms 1236 KB Output is correct
54 Correct 10 ms 2908 KB Output is correct
55 Correct 55 ms 8148 KB Output is correct
56 Correct 55 ms 8252 KB Output is correct
57 Correct 55 ms 8256 KB Output is correct
58 Correct 54 ms 8148 KB Output is correct
59 Correct 59 ms 8268 KB Output is correct
60 Correct 52 ms 8144 KB Output is correct
61 Correct 74 ms 8256 KB Output is correct
62 Correct 72 ms 8272 KB Output is correct
63 Correct 71 ms 8204 KB Output is correct
64 Correct 63 ms 8228 KB Output is correct
65 Correct 76 ms 8240 KB Output is correct
66 Correct 74 ms 8248 KB Output is correct
67 Correct 50 ms 8244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 389 ms 20760 KB Output is correct
14 Correct 419 ms 23572 KB Output is correct
15 Correct 450 ms 26784 KB Output is correct
16 Correct 594 ms 30172 KB Output is correct
17 Correct 678 ms 33880 KB Output is correct
18 Correct 646 ms 33884 KB Output is correct
19 Correct 618 ms 33988 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 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 212 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 304 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 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 312 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 436 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 436 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 304 KB Output is correct
52 Correct 1 ms 308 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 2 ms 1236 KB Output is correct
59 Correct 3 ms 1264 KB Output is correct
60 Correct 3 ms 1236 KB Output is correct
61 Correct 3 ms 1236 KB Output is correct
62 Correct 2 ms 1236 KB Output is correct
63 Correct 3 ms 1236 KB Output is correct
64 Correct 3 ms 1236 KB Output is correct
65 Correct 3 ms 1236 KB Output is correct
66 Correct 4 ms 1256 KB Output is correct
67 Correct 4 ms 1260 KB Output is correct
68 Correct 4 ms 1236 KB Output is correct
69 Correct 3 ms 1236 KB Output is correct
70 Correct 3 ms 1236 KB Output is correct
71 Correct 10 ms 2908 KB Output is correct
72 Correct 55 ms 8148 KB Output is correct
73 Correct 55 ms 8252 KB Output is correct
74 Correct 55 ms 8256 KB Output is correct
75 Correct 54 ms 8148 KB Output is correct
76 Correct 59 ms 8268 KB Output is correct
77 Correct 52 ms 8144 KB Output is correct
78 Correct 74 ms 8256 KB Output is correct
79 Correct 72 ms 8272 KB Output is correct
80 Correct 71 ms 8204 KB Output is correct
81 Correct 63 ms 8228 KB Output is correct
82 Correct 76 ms 8240 KB Output is correct
83 Correct 74 ms 8248 KB Output is correct
84 Correct 50 ms 8244 KB Output is correct
85 Correct 160 ms 16488 KB Output is correct
86 Correct 423 ms 34008 KB Output is correct
87 Correct 403 ms 33864 KB Output is correct
88 Correct 394 ms 33944 KB Output is correct
89 Correct 399 ms 33832 KB Output is correct
90 Correct 389 ms 33900 KB Output is correct
91 Correct 589 ms 33868 KB Output is correct
92 Correct 646 ms 33956 KB Output is correct
93 Correct 459 ms 33884 KB Output is correct
94 Correct 459 ms 33848 KB Output is correct
95 Correct 623 ms 33996 KB Output is correct
96 Correct 636 ms 33880 KB Output is correct
97 Correct 403 ms 33884 KB Output is correct