답안 #551762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551762 2022-04-21T13:02:05 Z kshitij_sodani Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
1092 ms 147620 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define a first
#define b second
#define pb push_back
const llo mod=1e9+7;
bool par[2501][2501][13];
llo ne[2501][2501];//
vector<llo> pre[2501];
llo it[2501];
llo dp[2501][2501];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n;
	cin>>n;
	string s;
	cin>>s;
	for(llo i=0;i<n;i++){
		it[i]=s[i]-'0';
	}
	llo aa,bb,cc;
	cin>>aa>>bb>>cc;
	for(llo i=0;i<n;i++){
		for(llo j=i;j<n;j++){
			if(it[i]==it[j]){
				par[i][j][0]=1;
			}
			else{
				par[i][j][1]=1;
			}
		}
	}
	for(llo j=1;j<13;j++){
		for(llo i=0;i<n;i++){
			for(llo k=i;k<n;k++){
				if(k+(1<<j)-1>=n){
					par[i][k][j]=0;
					continue;
				}
				par[i][k][j]=min(par[i][k][j-1],par[i+(1<<(j-1))][k+(1<<(j-1))][j-1]);
			}
		}
	}
	for(llo i=0;i<n;i++){
		for(llo j=0;j<=n;j++){
			pre[j].clear();
		}
		for(llo j=i+1;j<n;j++){
			llo su=0;
			llo aa=i;
			llo bb=j;
			for(llo k=12;k>=0;k--){
				if(bb+(1<<k)-1<n){
					if(par[aa][bb][k]==1){
						aa+=(1<<k);
						bb+=(1<<k);
						su+=(1<<k);
					}
				}
			}
			if(su==0){
				continue;
			}
			su=min(su,j-i);
			pre[su].pb(j);
		}
		llo mi=n;
		for(llo j=n;j>=1;j--){
			for(auto jj:pre[j]){
				mi=min(mi,jj);
			}
			if(mi<n){
				ne[i][j]=mi;
				//cout<<i<<":"<<j<<":"<<ne[i][j]<<endl;
			}
			else{
				ne[i][j]=-1;
			}
			
		}
	}
	//return 0;
	for(llo i=0;i<n;i++){
		for(llo j=0;j<n;j++){
			dp[i][j]=1e18;
		}
	}
	for(llo ii=0;ii<n;ii++){
		for(llo i=0;i+ii<n;i++){
			llo j=i+ii;
			if(i==j){
				dp[i][j]=min(dp[i][j],aa);
			}
			else{
				dp[i][j]=min(dp[i][j],min(dp[i][j-1]+aa,dp[i+1][j]+aa));
			}
			llo cur=i;
			llo su2=0;
			llo zz=1;
			while(true){
				if(zz>1){
					dp[i][cur+ii]=min(dp[i][cur+ii],su2*aa+dp[i][j]+bb+cc*zz);
					/*if(i==2 and j==4){
						cout<<cur<<":"<<endl;
						cout<<su2<<":"<<dp[i][j]<<":"<<zz<<endl;
					}*/
				}
				//cout<<i<<",,"<<j<<":"<<cur<<endl;
				
			/*	if(ne[cur][j-i+1]==0){
					cout<<cur<<":"<<j-i+1<<endl;
					return 0;
				}*/
				if(ne[cur][j-i+1]==-1){
					break;
				}
				su2+=ne[cur][j-i+1]-(cur+ii)-1;
				zz++;
				cur=ne[cur][j-i+1];

			}
		}
	}
	//cout<<dp[2][7]<<endl;

	cout<<dp[0][n-1]<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 388 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 441 ms 96012 KB Output is correct
4 Correct 533 ms 110284 KB Output is correct
5 Correct 672 ms 121884 KB Output is correct
6 Correct 806 ms 134128 KB Output is correct
7 Correct 1043 ms 147524 KB Output is correct
8 Correct 1092 ms 147592 KB Output is correct
9 Correct 1058 ms 147524 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 392 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 388 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 780 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 772 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 696 KB Output is correct
31 Correct 1 ms 780 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 388 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 780 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 772 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 696 KB Output is correct
31 Correct 1 ms 780 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 2 ms 1492 KB Output is correct
41 Correct 5 ms 3636 KB Output is correct
42 Correct 5 ms 3668 KB Output is correct
43 Correct 5 ms 3668 KB Output is correct
44 Correct 4 ms 3668 KB Output is correct
45 Correct 3 ms 3668 KB Output is correct
46 Correct 3 ms 3668 KB Output is correct
47 Correct 4 ms 3668 KB Output is correct
48 Correct 4 ms 3668 KB Output is correct
49 Correct 3 ms 3668 KB Output is correct
50 Correct 4 ms 3668 KB Output is correct
51 Correct 4 ms 3668 KB Output is correct
52 Correct 4 ms 3668 KB Output is correct
53 Correct 3 ms 3668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 388 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 780 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 772 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 696 KB Output is correct
31 Correct 1 ms 780 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 2 ms 1492 KB Output is correct
41 Correct 5 ms 3636 KB Output is correct
42 Correct 5 ms 3668 KB Output is correct
43 Correct 5 ms 3668 KB Output is correct
44 Correct 4 ms 3668 KB Output is correct
45 Correct 3 ms 3668 KB Output is correct
46 Correct 3 ms 3668 KB Output is correct
47 Correct 4 ms 3668 KB Output is correct
48 Correct 4 ms 3668 KB Output is correct
49 Correct 3 ms 3668 KB Output is correct
50 Correct 4 ms 3668 KB Output is correct
51 Correct 4 ms 3668 KB Output is correct
52 Correct 4 ms 3668 KB Output is correct
53 Correct 3 ms 3668 KB Output is correct
54 Correct 13 ms 10196 KB Output is correct
55 Correct 106 ms 34480 KB Output is correct
56 Correct 71 ms 34380 KB Output is correct
57 Correct 59 ms 34452 KB Output is correct
58 Correct 55 ms 34480 KB Output is correct
59 Correct 61 ms 34380 KB Output is correct
60 Correct 56 ms 34452 KB Output is correct
61 Correct 67 ms 34484 KB Output is correct
62 Correct 105 ms 34508 KB Output is correct
63 Correct 61 ms 34488 KB Output is correct
64 Correct 69 ms 34492 KB Output is correct
65 Correct 85 ms 34532 KB Output is correct
66 Correct 94 ms 34412 KB Output is correct
67 Correct 52 ms 34380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 388 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 441 ms 96012 KB Output is correct
14 Correct 533 ms 110284 KB Output is correct
15 Correct 672 ms 121884 KB Output is correct
16 Correct 806 ms 134128 KB Output is correct
17 Correct 1043 ms 147524 KB Output is correct
18 Correct 1092 ms 147592 KB Output is correct
19 Correct 1058 ms 147524 KB Output is correct
20 Correct 1 ms 340 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 392 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 780 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 1 ms 724 KB Output is correct
41 Correct 1 ms 724 KB Output is correct
42 Correct 1 ms 772 KB Output is correct
43 Correct 1 ms 724 KB Output is correct
44 Correct 1 ms 724 KB Output is correct
45 Correct 1 ms 724 KB Output is correct
46 Correct 1 ms 724 KB Output is correct
47 Correct 1 ms 696 KB Output is correct
48 Correct 1 ms 780 KB Output is correct
49 Correct 1 ms 724 KB Output is correct
50 Correct 1 ms 724 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 724 KB Output is correct
57 Correct 2 ms 1492 KB Output is correct
58 Correct 5 ms 3636 KB Output is correct
59 Correct 5 ms 3668 KB Output is correct
60 Correct 5 ms 3668 KB Output is correct
61 Correct 4 ms 3668 KB Output is correct
62 Correct 3 ms 3668 KB Output is correct
63 Correct 3 ms 3668 KB Output is correct
64 Correct 4 ms 3668 KB Output is correct
65 Correct 4 ms 3668 KB Output is correct
66 Correct 3 ms 3668 KB Output is correct
67 Correct 4 ms 3668 KB Output is correct
68 Correct 4 ms 3668 KB Output is correct
69 Correct 4 ms 3668 KB Output is correct
70 Correct 3 ms 3668 KB Output is correct
71 Correct 13 ms 10196 KB Output is correct
72 Correct 106 ms 34480 KB Output is correct
73 Correct 71 ms 34380 KB Output is correct
74 Correct 59 ms 34452 KB Output is correct
75 Correct 55 ms 34480 KB Output is correct
76 Correct 61 ms 34380 KB Output is correct
77 Correct 56 ms 34452 KB Output is correct
78 Correct 67 ms 34484 KB Output is correct
79 Correct 105 ms 34508 KB Output is correct
80 Correct 61 ms 34488 KB Output is correct
81 Correct 69 ms 34492 KB Output is correct
82 Correct 85 ms 34532 KB Output is correct
83 Correct 94 ms 34412 KB Output is correct
84 Correct 52 ms 34380 KB Output is correct
85 Correct 166 ms 74444 KB Output is correct
86 Correct 412 ms 147512 KB Output is correct
87 Correct 367 ms 147460 KB Output is correct
88 Correct 360 ms 147372 KB Output is correct
89 Correct 306 ms 147380 KB Output is correct
90 Correct 326 ms 147512 KB Output is correct
91 Correct 606 ms 147404 KB Output is correct
92 Correct 788 ms 147532 KB Output is correct
93 Correct 403 ms 147528 KB Output is correct
94 Correct 389 ms 147540 KB Output is correct
95 Correct 606 ms 147532 KB Output is correct
96 Correct 612 ms 147620 KB Output is correct
97 Correct 295 ms 147372 KB Output is correct