답안 #567729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567729 2022-05-24T06:01:43 Z errorgorn Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
1402 ms 98800 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
string s;
int a,b,c;

int memo[2505][2505]; //the answer
int nxt[2505][2505]; //(length,index)

void proc(vector<int> v,int len){
	sort(all(v));
	reverse(all(v));
	
	int idx=-1;
	for (auto it:v){
		if (it+len<=v[idx+1]) idx++;
		if (idx!=-1) nxt[len][it]=v[idx];
	}
	
	//cout<<len<<": "<<endl;
	//for (auto it:v) cout<<it<<" "; cout<<endl;
}

signed main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n>>s;
	cin>>a>>b>>c;
	
	vector<int> idx;
	rep(x,0,n) idx.pub(x);
	
	sort(all(idx),[](int i,int j){ //poor man's suffix array
		return s.substr(i,n-i)<s.substr(j,n-j);
	});
	
	//for (auto it:idx) cout<<it<<" "; cout<<endl;
	
	memset(nxt,-1,sizeof(nxt));
	rep(x,1,n+1){
		vector<int> temp;
		for (auto it:idx) if (it+x<=n) temp.pub(it);
		rep(y,0,sz(temp)-1) assert(s.substr(temp[y],x)<=s.substr(temp[y+1],x));
		temp.clear();
		
		for (auto it:idx) if (it+x<=n){
			if (!temp.empty() && s.substr(temp.back(),x)!=s.substr(it,x)){
				proc(temp,x);
				temp.clear();
			}
			
			temp.pub(it);
		}
		proc(temp,x);
	}
	
	//rep(x,1,n+1){
		//rep(y,0,n) cout<<nxt[x][y]<<" "; cout<<endl;
	//}
	
	memset(memo,1,sizeof(memo));
	
	rep(x,0,n) memo[x][x]=a;
	rep(len,1,n+1){
		rep(l,0,n+1-len){
			int r=l+len-1;
			
			if (l!=0) memo[l-1][r]=min(memo[l-1][r],memo[l][r]+a);
			if (r!=n-1) memo[l][r+1]=min(memo[l][r+1],memo[l][r]+a);
			
			int curr=l;
			int num=1;
			while (nxt[len][curr]!=-1){
				curr=nxt[len][curr];
				num++;
				
				int r2=curr+len-1;
				memo[l][r2]=min(memo[l][r2],
					memo[l][r]+b+num*c+(r2-l+1-num*len)*a);
			}
		}
	}
	
	cout<<memo[0][n-1]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 98532 KB Output is correct
2 Correct 39 ms 98508 KB Output is correct
3 Correct 39 ms 98432 KB Output is correct
4 Correct 39 ms 98516 KB Output is correct
5 Correct 37 ms 98508 KB Output is correct
6 Correct 38 ms 98516 KB Output is correct
7 Correct 37 ms 98448 KB Output is correct
8 Correct 38 ms 98508 KB Output is correct
9 Correct 40 ms 98524 KB Output is correct
10 Correct 45 ms 98636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 98492 KB Output is correct
2 Correct 37 ms 98516 KB Output is correct
3 Correct 645 ms 98744 KB Output is correct
4 Correct 766 ms 98592 KB Output is correct
5 Correct 898 ms 98692 KB Output is correct
6 Correct 1113 ms 98724 KB Output is correct
7 Correct 1293 ms 98604 KB Output is correct
8 Correct 1402 ms 98692 KB Output is correct
9 Correct 1343 ms 98688 KB Output is correct
10 Correct 44 ms 98588 KB Output is correct
11 Correct 38 ms 98516 KB Output is correct
12 Correct 38 ms 98456 KB Output is correct
13 Correct 39 ms 98444 KB Output is correct
14 Correct 38 ms 98492 KB Output is correct
15 Correct 37 ms 98504 KB Output is correct
16 Correct 38 ms 98508 KB Output is correct
17 Correct 36 ms 98480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 98532 KB Output is correct
2 Correct 39 ms 98508 KB Output is correct
3 Correct 39 ms 98432 KB Output is correct
4 Correct 39 ms 98516 KB Output is correct
5 Correct 37 ms 98508 KB Output is correct
6 Correct 38 ms 98516 KB Output is correct
7 Correct 37 ms 98448 KB Output is correct
8 Correct 38 ms 98508 KB Output is correct
9 Correct 40 ms 98524 KB Output is correct
10 Correct 45 ms 98636 KB Output is correct
11 Correct 44 ms 98536 KB Output is correct
12 Correct 38 ms 98436 KB Output is correct
13 Correct 39 ms 98476 KB Output is correct
14 Correct 37 ms 98496 KB Output is correct
15 Correct 36 ms 98448 KB Output is correct
16 Correct 38 ms 98652 KB Output is correct
17 Correct 38 ms 98524 KB Output is correct
18 Correct 37 ms 98428 KB Output is correct
19 Correct 40 ms 98508 KB Output is correct
20 Correct 40 ms 98424 KB Output is correct
21 Correct 40 ms 98528 KB Output is correct
22 Correct 39 ms 98456 KB Output is correct
23 Correct 38 ms 98444 KB Output is correct
24 Correct 39 ms 98436 KB Output is correct
25 Correct 40 ms 98424 KB Output is correct
26 Correct 41 ms 98508 KB Output is correct
27 Correct 43 ms 98500 KB Output is correct
28 Correct 38 ms 98468 KB Output is correct
29 Correct 43 ms 98436 KB Output is correct
30 Correct 39 ms 98508 KB Output is correct
31 Correct 40 ms 98452 KB Output is correct
32 Correct 45 ms 98544 KB Output is correct
33 Correct 39 ms 98504 KB Output is correct
34 Correct 38 ms 98444 KB Output is correct
35 Correct 37 ms 98448 KB Output is correct
36 Correct 40 ms 98512 KB Output is correct
37 Correct 44 ms 98604 KB Output is correct
38 Correct 38 ms 98452 KB Output is correct
39 Correct 45 ms 98476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 98532 KB Output is correct
2 Correct 39 ms 98508 KB Output is correct
3 Correct 39 ms 98432 KB Output is correct
4 Correct 39 ms 98516 KB Output is correct
5 Correct 37 ms 98508 KB Output is correct
6 Correct 38 ms 98516 KB Output is correct
7 Correct 37 ms 98448 KB Output is correct
8 Correct 38 ms 98508 KB Output is correct
9 Correct 40 ms 98524 KB Output is correct
10 Correct 45 ms 98636 KB Output is correct
11 Correct 44 ms 98536 KB Output is correct
12 Correct 38 ms 98436 KB Output is correct
13 Correct 39 ms 98476 KB Output is correct
14 Correct 37 ms 98496 KB Output is correct
15 Correct 36 ms 98448 KB Output is correct
16 Correct 38 ms 98652 KB Output is correct
17 Correct 38 ms 98524 KB Output is correct
18 Correct 37 ms 98428 KB Output is correct
19 Correct 40 ms 98508 KB Output is correct
20 Correct 40 ms 98424 KB Output is correct
21 Correct 40 ms 98528 KB Output is correct
22 Correct 39 ms 98456 KB Output is correct
23 Correct 38 ms 98444 KB Output is correct
24 Correct 39 ms 98436 KB Output is correct
25 Correct 40 ms 98424 KB Output is correct
26 Correct 41 ms 98508 KB Output is correct
27 Correct 43 ms 98500 KB Output is correct
28 Correct 38 ms 98468 KB Output is correct
29 Correct 43 ms 98436 KB Output is correct
30 Correct 39 ms 98508 KB Output is correct
31 Correct 40 ms 98452 KB Output is correct
32 Correct 45 ms 98544 KB Output is correct
33 Correct 39 ms 98504 KB Output is correct
34 Correct 38 ms 98444 KB Output is correct
35 Correct 37 ms 98448 KB Output is correct
36 Correct 40 ms 98512 KB Output is correct
37 Correct 44 ms 98604 KB Output is correct
38 Correct 38 ms 98452 KB Output is correct
39 Correct 45 ms 98476 KB Output is correct
40 Correct 41 ms 98536 KB Output is correct
41 Correct 40 ms 98552 KB Output is correct
42 Correct 42 ms 98444 KB Output is correct
43 Correct 43 ms 98492 KB Output is correct
44 Correct 44 ms 98512 KB Output is correct
45 Correct 42 ms 98512 KB Output is correct
46 Correct 53 ms 98496 KB Output is correct
47 Correct 53 ms 98456 KB Output is correct
48 Correct 42 ms 98516 KB Output is correct
49 Correct 42 ms 98508 KB Output is correct
50 Correct 41 ms 98544 KB Output is correct
51 Correct 41 ms 98464 KB Output is correct
52 Correct 43 ms 98500 KB Output is correct
53 Correct 49 ms 98440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 98532 KB Output is correct
2 Correct 39 ms 98508 KB Output is correct
3 Correct 39 ms 98432 KB Output is correct
4 Correct 39 ms 98516 KB Output is correct
5 Correct 37 ms 98508 KB Output is correct
6 Correct 38 ms 98516 KB Output is correct
7 Correct 37 ms 98448 KB Output is correct
8 Correct 38 ms 98508 KB Output is correct
9 Correct 40 ms 98524 KB Output is correct
10 Correct 45 ms 98636 KB Output is correct
11 Correct 44 ms 98536 KB Output is correct
12 Correct 38 ms 98436 KB Output is correct
13 Correct 39 ms 98476 KB Output is correct
14 Correct 37 ms 98496 KB Output is correct
15 Correct 36 ms 98448 KB Output is correct
16 Correct 38 ms 98652 KB Output is correct
17 Correct 38 ms 98524 KB Output is correct
18 Correct 37 ms 98428 KB Output is correct
19 Correct 40 ms 98508 KB Output is correct
20 Correct 40 ms 98424 KB Output is correct
21 Correct 40 ms 98528 KB Output is correct
22 Correct 39 ms 98456 KB Output is correct
23 Correct 38 ms 98444 KB Output is correct
24 Correct 39 ms 98436 KB Output is correct
25 Correct 40 ms 98424 KB Output is correct
26 Correct 41 ms 98508 KB Output is correct
27 Correct 43 ms 98500 KB Output is correct
28 Correct 38 ms 98468 KB Output is correct
29 Correct 43 ms 98436 KB Output is correct
30 Correct 39 ms 98508 KB Output is correct
31 Correct 40 ms 98452 KB Output is correct
32 Correct 45 ms 98544 KB Output is correct
33 Correct 39 ms 98504 KB Output is correct
34 Correct 38 ms 98444 KB Output is correct
35 Correct 37 ms 98448 KB Output is correct
36 Correct 40 ms 98512 KB Output is correct
37 Correct 44 ms 98604 KB Output is correct
38 Correct 38 ms 98452 KB Output is correct
39 Correct 45 ms 98476 KB Output is correct
40 Correct 41 ms 98536 KB Output is correct
41 Correct 40 ms 98552 KB Output is correct
42 Correct 42 ms 98444 KB Output is correct
43 Correct 43 ms 98492 KB Output is correct
44 Correct 44 ms 98512 KB Output is correct
45 Correct 42 ms 98512 KB Output is correct
46 Correct 53 ms 98496 KB Output is correct
47 Correct 53 ms 98456 KB Output is correct
48 Correct 42 ms 98516 KB Output is correct
49 Correct 42 ms 98508 KB Output is correct
50 Correct 41 ms 98544 KB Output is correct
51 Correct 41 ms 98464 KB Output is correct
52 Correct 43 ms 98500 KB Output is correct
53 Correct 49 ms 98440 KB Output is correct
54 Correct 59 ms 98496 KB Output is correct
55 Correct 160 ms 98548 KB Output is correct
56 Correct 145 ms 98508 KB Output is correct
57 Correct 152 ms 98580 KB Output is correct
58 Correct 145 ms 98560 KB Output is correct
59 Correct 139 ms 98628 KB Output is correct
60 Correct 149 ms 98544 KB Output is correct
61 Correct 151 ms 98528 KB Output is correct
62 Correct 150 ms 98632 KB Output is correct
63 Correct 163 ms 98624 KB Output is correct
64 Correct 163 ms 98532 KB Output is correct
65 Correct 157 ms 98632 KB Output is correct
66 Correct 169 ms 98620 KB Output is correct
67 Correct 148 ms 98528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 98532 KB Output is correct
2 Correct 39 ms 98508 KB Output is correct
3 Correct 39 ms 98432 KB Output is correct
4 Correct 39 ms 98516 KB Output is correct
5 Correct 37 ms 98508 KB Output is correct
6 Correct 38 ms 98516 KB Output is correct
7 Correct 37 ms 98448 KB Output is correct
8 Correct 38 ms 98508 KB Output is correct
9 Correct 40 ms 98524 KB Output is correct
10 Correct 45 ms 98636 KB Output is correct
11 Correct 43 ms 98492 KB Output is correct
12 Correct 37 ms 98516 KB Output is correct
13 Correct 645 ms 98744 KB Output is correct
14 Correct 766 ms 98592 KB Output is correct
15 Correct 898 ms 98692 KB Output is correct
16 Correct 1113 ms 98724 KB Output is correct
17 Correct 1293 ms 98604 KB Output is correct
18 Correct 1402 ms 98692 KB Output is correct
19 Correct 1343 ms 98688 KB Output is correct
20 Correct 44 ms 98588 KB Output is correct
21 Correct 38 ms 98516 KB Output is correct
22 Correct 38 ms 98456 KB Output is correct
23 Correct 39 ms 98444 KB Output is correct
24 Correct 38 ms 98492 KB Output is correct
25 Correct 37 ms 98504 KB Output is correct
26 Correct 38 ms 98508 KB Output is correct
27 Correct 36 ms 98480 KB Output is correct
28 Correct 44 ms 98536 KB Output is correct
29 Correct 38 ms 98436 KB Output is correct
30 Correct 39 ms 98476 KB Output is correct
31 Correct 37 ms 98496 KB Output is correct
32 Correct 36 ms 98448 KB Output is correct
33 Correct 38 ms 98652 KB Output is correct
34 Correct 38 ms 98524 KB Output is correct
35 Correct 37 ms 98428 KB Output is correct
36 Correct 40 ms 98508 KB Output is correct
37 Correct 40 ms 98424 KB Output is correct
38 Correct 40 ms 98528 KB Output is correct
39 Correct 39 ms 98456 KB Output is correct
40 Correct 38 ms 98444 KB Output is correct
41 Correct 39 ms 98436 KB Output is correct
42 Correct 40 ms 98424 KB Output is correct
43 Correct 41 ms 98508 KB Output is correct
44 Correct 43 ms 98500 KB Output is correct
45 Correct 38 ms 98468 KB Output is correct
46 Correct 43 ms 98436 KB Output is correct
47 Correct 39 ms 98508 KB Output is correct
48 Correct 40 ms 98452 KB Output is correct
49 Correct 45 ms 98544 KB Output is correct
50 Correct 39 ms 98504 KB Output is correct
51 Correct 38 ms 98444 KB Output is correct
52 Correct 37 ms 98448 KB Output is correct
53 Correct 40 ms 98512 KB Output is correct
54 Correct 44 ms 98604 KB Output is correct
55 Correct 38 ms 98452 KB Output is correct
56 Correct 45 ms 98476 KB Output is correct
57 Correct 41 ms 98536 KB Output is correct
58 Correct 40 ms 98552 KB Output is correct
59 Correct 42 ms 98444 KB Output is correct
60 Correct 43 ms 98492 KB Output is correct
61 Correct 44 ms 98512 KB Output is correct
62 Correct 42 ms 98512 KB Output is correct
63 Correct 53 ms 98496 KB Output is correct
64 Correct 53 ms 98456 KB Output is correct
65 Correct 42 ms 98516 KB Output is correct
66 Correct 42 ms 98508 KB Output is correct
67 Correct 41 ms 98544 KB Output is correct
68 Correct 41 ms 98464 KB Output is correct
69 Correct 43 ms 98500 KB Output is correct
70 Correct 49 ms 98440 KB Output is correct
71 Correct 59 ms 98496 KB Output is correct
72 Correct 160 ms 98548 KB Output is correct
73 Correct 145 ms 98508 KB Output is correct
74 Correct 152 ms 98580 KB Output is correct
75 Correct 145 ms 98560 KB Output is correct
76 Correct 139 ms 98628 KB Output is correct
77 Correct 149 ms 98544 KB Output is correct
78 Correct 151 ms 98528 KB Output is correct
79 Correct 150 ms 98632 KB Output is correct
80 Correct 163 ms 98624 KB Output is correct
81 Correct 163 ms 98532 KB Output is correct
82 Correct 157 ms 98632 KB Output is correct
83 Correct 169 ms 98620 KB Output is correct
84 Correct 148 ms 98528 KB Output is correct
85 Correct 358 ms 98556 KB Output is correct
86 Correct 1051 ms 98588 KB Output is correct
87 Correct 1077 ms 98712 KB Output is correct
88 Correct 1060 ms 98592 KB Output is correct
89 Correct 1055 ms 98596 KB Output is correct
90 Correct 1117 ms 98636 KB Output is correct
91 Correct 1206 ms 98800 KB Output is correct
92 Correct 1273 ms 98704 KB Output is correct
93 Correct 1138 ms 98676 KB Output is correct
94 Correct 1187 ms 98588 KB Output is correct
95 Incorrect 1263 ms 98704 KB Output isn't correct
96 Halted 0 ms 0 KB -