Submission #567718

# Submission time Handle Problem Language Result Execution time Memory
567718 2022-05-24T05:49:22 Z errorgorn Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
884 ms 392760 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[5005][5005]; //the answer
int nxt[5005][5005]; //(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){
			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,63,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;
}
# Verdict Execution time Memory Grader output
1 Correct 150 ms 392476 KB Output is correct
2 Correct 144 ms 392368 KB Output is correct
3 Correct 143 ms 392424 KB Output is correct
4 Correct 143 ms 392460 KB Output is correct
5 Correct 146 ms 392392 KB Output is correct
6 Correct 149 ms 392436 KB Output is correct
7 Correct 146 ms 392368 KB Output is correct
8 Correct 149 ms 392424 KB Output is correct
9 Correct 155 ms 392396 KB Output is correct
10 Correct 140 ms 392464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 392516 KB Output is correct
2 Correct 152 ms 392392 KB Output is correct
3 Correct 479 ms 392524 KB Output is correct
4 Correct 558 ms 392700 KB Output is correct
5 Correct 658 ms 392628 KB Output is correct
6 Correct 761 ms 392508 KB Output is correct
7 Correct 873 ms 392628 KB Output is correct
8 Correct 865 ms 392636 KB Output is correct
9 Correct 884 ms 392760 KB Output is correct
10 Correct 147 ms 392368 KB Output is correct
11 Correct 147 ms 392380 KB Output is correct
12 Correct 165 ms 392376 KB Output is correct
13 Correct 145 ms 392396 KB Output is correct
14 Correct 149 ms 392508 KB Output is correct
15 Correct 155 ms 392456 KB Output is correct
16 Correct 149 ms 392524 KB Output is correct
17 Correct 145 ms 392460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 392476 KB Output is correct
2 Correct 144 ms 392368 KB Output is correct
3 Correct 143 ms 392424 KB Output is correct
4 Correct 143 ms 392460 KB Output is correct
5 Correct 146 ms 392392 KB Output is correct
6 Correct 149 ms 392436 KB Output is correct
7 Correct 146 ms 392368 KB Output is correct
8 Correct 149 ms 392424 KB Output is correct
9 Correct 155 ms 392396 KB Output is correct
10 Correct 140 ms 392464 KB Output is correct
11 Correct 151 ms 392456 KB Output is correct
12 Correct 149 ms 392472 KB Output is correct
13 Correct 146 ms 392372 KB Output is correct
14 Correct 153 ms 392396 KB Output is correct
15 Correct 147 ms 392456 KB Output is correct
16 Correct 149 ms 392404 KB Output is correct
17 Correct 154 ms 392464 KB Output is correct
18 Correct 146 ms 392428 KB Output is correct
19 Correct 145 ms 392436 KB Output is correct
20 Correct 153 ms 392452 KB Output is correct
21 Correct 177 ms 392384 KB Output is correct
22 Correct 143 ms 392476 KB Output is correct
23 Correct 143 ms 392392 KB Output is correct
24 Correct 155 ms 392452 KB Output is correct
25 Correct 154 ms 392396 KB Output is correct
26 Correct 144 ms 392360 KB Output is correct
27 Correct 150 ms 392396 KB Output is correct
28 Correct 148 ms 392396 KB Output is correct
29 Correct 150 ms 392456 KB Output is correct
30 Correct 150 ms 392484 KB Output is correct
31 Correct 152 ms 392404 KB Output is correct
32 Correct 162 ms 392440 KB Output is correct
33 Correct 164 ms 392528 KB Output is correct
34 Correct 152 ms 392388 KB Output is correct
35 Correct 149 ms 392396 KB Output is correct
36 Correct 165 ms 392444 KB Output is correct
37 Correct 162 ms 392396 KB Output is correct
38 Correct 149 ms 392460 KB Output is correct
39 Correct 160 ms 392476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 392476 KB Output is correct
2 Correct 144 ms 392368 KB Output is correct
3 Correct 143 ms 392424 KB Output is correct
4 Correct 143 ms 392460 KB Output is correct
5 Correct 146 ms 392392 KB Output is correct
6 Correct 149 ms 392436 KB Output is correct
7 Correct 146 ms 392368 KB Output is correct
8 Correct 149 ms 392424 KB Output is correct
9 Correct 155 ms 392396 KB Output is correct
10 Correct 140 ms 392464 KB Output is correct
11 Correct 151 ms 392456 KB Output is correct
12 Correct 149 ms 392472 KB Output is correct
13 Correct 146 ms 392372 KB Output is correct
14 Correct 153 ms 392396 KB Output is correct
15 Correct 147 ms 392456 KB Output is correct
16 Correct 149 ms 392404 KB Output is correct
17 Correct 154 ms 392464 KB Output is correct
18 Correct 146 ms 392428 KB Output is correct
19 Correct 145 ms 392436 KB Output is correct
20 Correct 153 ms 392452 KB Output is correct
21 Correct 177 ms 392384 KB Output is correct
22 Correct 143 ms 392476 KB Output is correct
23 Correct 143 ms 392392 KB Output is correct
24 Correct 155 ms 392452 KB Output is correct
25 Correct 154 ms 392396 KB Output is correct
26 Correct 144 ms 392360 KB Output is correct
27 Correct 150 ms 392396 KB Output is correct
28 Correct 148 ms 392396 KB Output is correct
29 Correct 150 ms 392456 KB Output is correct
30 Correct 150 ms 392484 KB Output is correct
31 Correct 152 ms 392404 KB Output is correct
32 Correct 162 ms 392440 KB Output is correct
33 Correct 164 ms 392528 KB Output is correct
34 Correct 152 ms 392388 KB Output is correct
35 Correct 149 ms 392396 KB Output is correct
36 Correct 165 ms 392444 KB Output is correct
37 Correct 162 ms 392396 KB Output is correct
38 Correct 149 ms 392460 KB Output is correct
39 Correct 160 ms 392476 KB Output is correct
40 Correct 151 ms 392476 KB Output is correct
41 Correct 164 ms 392420 KB Output is correct
42 Correct 174 ms 392372 KB Output is correct
43 Correct 153 ms 392504 KB Output is correct
44 Correct 167 ms 392384 KB Output is correct
45 Correct 153 ms 392392 KB Output is correct
46 Correct 149 ms 392504 KB Output is correct
47 Correct 165 ms 392400 KB Output is correct
48 Correct 149 ms 392472 KB Output is correct
49 Correct 143 ms 392460 KB Output is correct
50 Correct 168 ms 392464 KB Output is correct
51 Correct 153 ms 392444 KB Output is correct
52 Correct 151 ms 392444 KB Output is correct
53 Correct 151 ms 392616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 392476 KB Output is correct
2 Correct 144 ms 392368 KB Output is correct
3 Correct 143 ms 392424 KB Output is correct
4 Correct 143 ms 392460 KB Output is correct
5 Correct 146 ms 392392 KB Output is correct
6 Correct 149 ms 392436 KB Output is correct
7 Correct 146 ms 392368 KB Output is correct
8 Correct 149 ms 392424 KB Output is correct
9 Correct 155 ms 392396 KB Output is correct
10 Correct 140 ms 392464 KB Output is correct
11 Correct 151 ms 392456 KB Output is correct
12 Correct 149 ms 392472 KB Output is correct
13 Correct 146 ms 392372 KB Output is correct
14 Correct 153 ms 392396 KB Output is correct
15 Correct 147 ms 392456 KB Output is correct
16 Correct 149 ms 392404 KB Output is correct
17 Correct 154 ms 392464 KB Output is correct
18 Correct 146 ms 392428 KB Output is correct
19 Correct 145 ms 392436 KB Output is correct
20 Correct 153 ms 392452 KB Output is correct
21 Correct 177 ms 392384 KB Output is correct
22 Correct 143 ms 392476 KB Output is correct
23 Correct 143 ms 392392 KB Output is correct
24 Correct 155 ms 392452 KB Output is correct
25 Correct 154 ms 392396 KB Output is correct
26 Correct 144 ms 392360 KB Output is correct
27 Correct 150 ms 392396 KB Output is correct
28 Correct 148 ms 392396 KB Output is correct
29 Correct 150 ms 392456 KB Output is correct
30 Correct 150 ms 392484 KB Output is correct
31 Correct 152 ms 392404 KB Output is correct
32 Correct 162 ms 392440 KB Output is correct
33 Correct 164 ms 392528 KB Output is correct
34 Correct 152 ms 392388 KB Output is correct
35 Correct 149 ms 392396 KB Output is correct
36 Correct 165 ms 392444 KB Output is correct
37 Correct 162 ms 392396 KB Output is correct
38 Correct 149 ms 392460 KB Output is correct
39 Correct 160 ms 392476 KB Output is correct
40 Correct 151 ms 392476 KB Output is correct
41 Correct 164 ms 392420 KB Output is correct
42 Correct 174 ms 392372 KB Output is correct
43 Correct 153 ms 392504 KB Output is correct
44 Correct 167 ms 392384 KB Output is correct
45 Correct 153 ms 392392 KB Output is correct
46 Correct 149 ms 392504 KB Output is correct
47 Correct 165 ms 392400 KB Output is correct
48 Correct 149 ms 392472 KB Output is correct
49 Correct 143 ms 392460 KB Output is correct
50 Correct 168 ms 392464 KB Output is correct
51 Correct 153 ms 392444 KB Output is correct
52 Correct 151 ms 392444 KB Output is correct
53 Correct 151 ms 392616 KB Output is correct
54 Correct 170 ms 392396 KB Output is correct
55 Correct 209 ms 392508 KB Output is correct
56 Correct 204 ms 392504 KB Output is correct
57 Correct 228 ms 392468 KB Output is correct
58 Correct 205 ms 392524 KB Output is correct
59 Correct 211 ms 392540 KB Output is correct
60 Correct 222 ms 392544 KB Output is correct
61 Correct 251 ms 392540 KB Output is correct
62 Correct 242 ms 392668 KB Output is correct
63 Correct 225 ms 392516 KB Output is correct
64 Correct 217 ms 392456 KB Output is correct
65 Correct 221 ms 392556 KB Output is correct
66 Correct 240 ms 392576 KB Output is correct
67 Correct 200 ms 392484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 392476 KB Output is correct
2 Correct 144 ms 392368 KB Output is correct
3 Correct 143 ms 392424 KB Output is correct
4 Correct 143 ms 392460 KB Output is correct
5 Correct 146 ms 392392 KB Output is correct
6 Correct 149 ms 392436 KB Output is correct
7 Correct 146 ms 392368 KB Output is correct
8 Correct 149 ms 392424 KB Output is correct
9 Correct 155 ms 392396 KB Output is correct
10 Correct 140 ms 392464 KB Output is correct
11 Correct 147 ms 392516 KB Output is correct
12 Correct 152 ms 392392 KB Output is correct
13 Correct 479 ms 392524 KB Output is correct
14 Correct 558 ms 392700 KB Output is correct
15 Correct 658 ms 392628 KB Output is correct
16 Correct 761 ms 392508 KB Output is correct
17 Correct 873 ms 392628 KB Output is correct
18 Correct 865 ms 392636 KB Output is correct
19 Correct 884 ms 392760 KB Output is correct
20 Correct 147 ms 392368 KB Output is correct
21 Correct 147 ms 392380 KB Output is correct
22 Correct 165 ms 392376 KB Output is correct
23 Correct 145 ms 392396 KB Output is correct
24 Correct 149 ms 392508 KB Output is correct
25 Correct 155 ms 392456 KB Output is correct
26 Correct 149 ms 392524 KB Output is correct
27 Correct 145 ms 392460 KB Output is correct
28 Correct 151 ms 392456 KB Output is correct
29 Correct 149 ms 392472 KB Output is correct
30 Correct 146 ms 392372 KB Output is correct
31 Correct 153 ms 392396 KB Output is correct
32 Correct 147 ms 392456 KB Output is correct
33 Correct 149 ms 392404 KB Output is correct
34 Correct 154 ms 392464 KB Output is correct
35 Correct 146 ms 392428 KB Output is correct
36 Correct 145 ms 392436 KB Output is correct
37 Correct 153 ms 392452 KB Output is correct
38 Correct 177 ms 392384 KB Output is correct
39 Correct 143 ms 392476 KB Output is correct
40 Correct 143 ms 392392 KB Output is correct
41 Correct 155 ms 392452 KB Output is correct
42 Correct 154 ms 392396 KB Output is correct
43 Correct 144 ms 392360 KB Output is correct
44 Correct 150 ms 392396 KB Output is correct
45 Correct 148 ms 392396 KB Output is correct
46 Correct 150 ms 392456 KB Output is correct
47 Correct 150 ms 392484 KB Output is correct
48 Correct 152 ms 392404 KB Output is correct
49 Correct 162 ms 392440 KB Output is correct
50 Correct 164 ms 392528 KB Output is correct
51 Correct 152 ms 392388 KB Output is correct
52 Correct 149 ms 392396 KB Output is correct
53 Correct 165 ms 392444 KB Output is correct
54 Correct 162 ms 392396 KB Output is correct
55 Correct 149 ms 392460 KB Output is correct
56 Correct 160 ms 392476 KB Output is correct
57 Correct 151 ms 392476 KB Output is correct
58 Correct 164 ms 392420 KB Output is correct
59 Correct 174 ms 392372 KB Output is correct
60 Correct 153 ms 392504 KB Output is correct
61 Correct 167 ms 392384 KB Output is correct
62 Correct 153 ms 392392 KB Output is correct
63 Correct 149 ms 392504 KB Output is correct
64 Correct 165 ms 392400 KB Output is correct
65 Correct 149 ms 392472 KB Output is correct
66 Correct 143 ms 392460 KB Output is correct
67 Correct 168 ms 392464 KB Output is correct
68 Correct 153 ms 392444 KB Output is correct
69 Correct 151 ms 392444 KB Output is correct
70 Correct 151 ms 392616 KB Output is correct
71 Correct 170 ms 392396 KB Output is correct
72 Correct 209 ms 392508 KB Output is correct
73 Correct 204 ms 392504 KB Output is correct
74 Correct 228 ms 392468 KB Output is correct
75 Correct 205 ms 392524 KB Output is correct
76 Correct 211 ms 392540 KB Output is correct
77 Correct 222 ms 392544 KB Output is correct
78 Correct 251 ms 392540 KB Output is correct
79 Correct 242 ms 392668 KB Output is correct
80 Correct 225 ms 392516 KB Output is correct
81 Correct 217 ms 392456 KB Output is correct
82 Correct 221 ms 392556 KB Output is correct
83 Correct 240 ms 392576 KB Output is correct
84 Correct 200 ms 392484 KB Output is correct
85 Correct 348 ms 392460 KB Output is correct
86 Correct 681 ms 392476 KB Output is correct
87 Correct 725 ms 392500 KB Output is correct
88 Correct 661 ms 392492 KB Output is correct
89 Correct 656 ms 392640 KB Output is correct
90 Correct 685 ms 392584 KB Output is correct
91 Correct 706 ms 392680 KB Output is correct
92 Correct 818 ms 392652 KB Output is correct
93 Correct 722 ms 392580 KB Output is correct
94 Correct 778 ms 392704 KB Output is correct
95 Incorrect 826 ms 392640 KB Output isn't correct
96 Halted 0 ms 0 KB -