답안 #733786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733786 2023-05-01T10:10:03 Z myrcella Copy and Paste 3 (JOI22_copypaste3) C++17
30 / 100
405 ms 89620 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define ALL(x) x.begin(),x.end()
int lowbit(int x) {return x&(-x);}

const int maxn = 222;

int n;
ll A,B,C;
string s;
int a[maxn];
int len[maxn][maxn];
ll f[maxn][maxn][maxn],g[maxn][maxn];
ll ans[maxn*20];
pq <pair<pair<ll,int>,pii>,vector<pair<pair<ll,int>,pii>>,greater<pair<pair<ll,int>,pii>>> q;

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie(0);
	memset(f,inf,sizeof(f));
	cin>>n>>s>>A>>B>>C;
	if (n>maxn) {
		ans[1] = A;
		rep(i,2,n+1) {
			ans[i] = i*A;
			rep(j,1,i) ans[i] = min(ans[i],ans[j] + B + C*(i/j) + A*(i%j));
		}
		cout<<ans[n];
		return 0;
	}
	rep(i,0,n) a[i] = (int)(s[i]-'a');
	rep(i,0,n)
		rep(j,i+1,n) {
			int x = i,y = j;
			while (y<n and a[x]==a[y]) x++,y++;
			len[i][j] = y-j; 
		}
	memset(f,inf,sizeof(f));
	memset(g,inf,sizeof(g));
	rep(i,0,n)
		rep(j,i,n) {
			g[i][j] = (j-i+1)*A + B;
			q.push({{g[i][j],-1},{i,j}});
		}
	while (!q.empty()) {
		if (q.top().fi.se==-1) { //g
			int i = q.top().se.fi, j = q.top().se.se;
			ll d = q.top().fi.fi;
			q.pop();
			if (g[i][j]!=d) continue;
			// update f
			if (f[i][j][j] > d + C) f[i][j][j] = d + C, q.push({{d+C,j},{i,j}});
			if (i-1>=0 and g[i-1][j] > d + A) g[i-1][j] = d + A, q.push({{d+A,-1},{i-1,j}});
		}
		else { //f
			int i = q.top().se.fi, j = q.top().se.se, k = q.top().fi.se;
			ll d = q.top().fi.fi;
			q.pop();
			if (f[i][j][k]!=d) continue;
			if (len[i][k+1] >= j-i+1 and f[i][j][k+j-i+1] > d + C) f[i][j][k+j-i+1] = d + C, q.push({{d+C,k+j-i+1},{i,j}});
			if (k+1<n and f[i][j][k+1] > d + A) f[i][j][k+1] = d + A, q.push({{d+A,k+1},{i,j}});
			if (g[i][k] > d + B) g[i][k] = d + B, q.push({{d+B,-1},{i,k}});
		}
	}
	ll ans = min(n*A,g[0][n-1] - B);
	rep(i,0,n) ans = min(ans,f[0][i][n-1]);
	cout<<ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 86224 KB Output is correct
2 Correct 43 ms 86224 KB Output is correct
3 Correct 42 ms 86236 KB Output is correct
4 Correct 42 ms 86348 KB Output is correct
5 Correct 44 ms 86352 KB Output is correct
6 Correct 42 ms 86348 KB Output is correct
7 Correct 41 ms 86308 KB Output is correct
8 Correct 44 ms 86216 KB Output is correct
9 Correct 43 ms 86296 KB Output is correct
10 Correct 42 ms 86336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 86344 KB Output is correct
2 Correct 43 ms 86328 KB Output is correct
3 Correct 44 ms 86100 KB Output is correct
4 Correct 43 ms 85912 KB Output is correct
5 Correct 44 ms 85908 KB Output is correct
6 Correct 48 ms 86020 KB Output is correct
7 Correct 49 ms 85972 KB Output is correct
8 Correct 49 ms 85940 KB Output is correct
9 Correct 51 ms 85956 KB Output is correct
10 Correct 43 ms 86360 KB Output is correct
11 Correct 42 ms 86220 KB Output is correct
12 Correct 43 ms 86220 KB Output is correct
13 Correct 43 ms 86224 KB Output is correct
14 Correct 42 ms 86344 KB Output is correct
15 Correct 43 ms 86264 KB Output is correct
16 Correct 44 ms 86340 KB Output is correct
17 Correct 42 ms 86328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 86224 KB Output is correct
2 Correct 43 ms 86224 KB Output is correct
3 Correct 42 ms 86236 KB Output is correct
4 Correct 42 ms 86348 KB Output is correct
5 Correct 44 ms 86352 KB Output is correct
6 Correct 42 ms 86348 KB Output is correct
7 Correct 41 ms 86308 KB Output is correct
8 Correct 44 ms 86216 KB Output is correct
9 Correct 43 ms 86296 KB Output is correct
10 Correct 42 ms 86336 KB Output is correct
11 Correct 50 ms 86284 KB Output is correct
12 Correct 44 ms 86344 KB Output is correct
13 Correct 46 ms 86328 KB Output is correct
14 Correct 43 ms 86348 KB Output is correct
15 Correct 43 ms 86356 KB Output is correct
16 Correct 44 ms 86368 KB Output is correct
17 Correct 47 ms 86336 KB Output is correct
18 Correct 43 ms 86220 KB Output is correct
19 Correct 42 ms 86296 KB Output is correct
20 Correct 43 ms 86236 KB Output is correct
21 Correct 44 ms 86448 KB Output is correct
22 Correct 44 ms 86384 KB Output is correct
23 Correct 43 ms 86340 KB Output is correct
24 Correct 46 ms 86340 KB Output is correct
25 Correct 43 ms 86300 KB Output is correct
26 Correct 43 ms 86360 KB Output is correct
27 Correct 43 ms 86324 KB Output is correct
28 Correct 43 ms 86288 KB Output is correct
29 Correct 44 ms 86428 KB Output is correct
30 Correct 48 ms 86368 KB Output is correct
31 Correct 49 ms 86288 KB Output is correct
32 Correct 48 ms 86316 KB Output is correct
33 Correct 42 ms 86360 KB Output is correct
34 Correct 44 ms 86248 KB Output is correct
35 Correct 43 ms 86220 KB Output is correct
36 Correct 42 ms 86344 KB Output is correct
37 Correct 45 ms 86352 KB Output is correct
38 Correct 43 ms 86348 KB Output is correct
39 Correct 43 ms 86304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 86224 KB Output is correct
2 Correct 43 ms 86224 KB Output is correct
3 Correct 42 ms 86236 KB Output is correct
4 Correct 42 ms 86348 KB Output is correct
5 Correct 44 ms 86352 KB Output is correct
6 Correct 42 ms 86348 KB Output is correct
7 Correct 41 ms 86308 KB Output is correct
8 Correct 44 ms 86216 KB Output is correct
9 Correct 43 ms 86296 KB Output is correct
10 Correct 42 ms 86336 KB Output is correct
11 Correct 50 ms 86284 KB Output is correct
12 Correct 44 ms 86344 KB Output is correct
13 Correct 46 ms 86328 KB Output is correct
14 Correct 43 ms 86348 KB Output is correct
15 Correct 43 ms 86356 KB Output is correct
16 Correct 44 ms 86368 KB Output is correct
17 Correct 47 ms 86336 KB Output is correct
18 Correct 43 ms 86220 KB Output is correct
19 Correct 42 ms 86296 KB Output is correct
20 Correct 43 ms 86236 KB Output is correct
21 Correct 44 ms 86448 KB Output is correct
22 Correct 44 ms 86384 KB Output is correct
23 Correct 43 ms 86340 KB Output is correct
24 Correct 46 ms 86340 KB Output is correct
25 Correct 43 ms 86300 KB Output is correct
26 Correct 43 ms 86360 KB Output is correct
27 Correct 43 ms 86324 KB Output is correct
28 Correct 43 ms 86288 KB Output is correct
29 Correct 44 ms 86428 KB Output is correct
30 Correct 48 ms 86368 KB Output is correct
31 Correct 49 ms 86288 KB Output is correct
32 Correct 48 ms 86316 KB Output is correct
33 Correct 42 ms 86360 KB Output is correct
34 Correct 44 ms 86248 KB Output is correct
35 Correct 43 ms 86220 KB Output is correct
36 Correct 42 ms 86344 KB Output is correct
37 Correct 45 ms 86352 KB Output is correct
38 Correct 43 ms 86348 KB Output is correct
39 Correct 43 ms 86304 KB Output is correct
40 Correct 63 ms 86508 KB Output is correct
41 Correct 405 ms 89620 KB Output is correct
42 Correct 328 ms 87368 KB Output is correct
43 Correct 312 ms 87316 KB Output is correct
44 Correct 342 ms 87444 KB Output is correct
45 Correct 291 ms 87376 KB Output is correct
46 Correct 289 ms 87368 KB Output is correct
47 Correct 325 ms 88124 KB Output is correct
48 Correct 292 ms 87348 KB Output is correct
49 Correct 288 ms 87396 KB Output is correct
50 Correct 301 ms 87412 KB Output is correct
51 Correct 325 ms 88172 KB Output is correct
52 Correct 334 ms 88128 KB Output is correct
53 Correct 269 ms 87320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 86224 KB Output is correct
2 Correct 43 ms 86224 KB Output is correct
3 Correct 42 ms 86236 KB Output is correct
4 Correct 42 ms 86348 KB Output is correct
5 Correct 44 ms 86352 KB Output is correct
6 Correct 42 ms 86348 KB Output is correct
7 Correct 41 ms 86308 KB Output is correct
8 Correct 44 ms 86216 KB Output is correct
9 Correct 43 ms 86296 KB Output is correct
10 Correct 42 ms 86336 KB Output is correct
11 Correct 50 ms 86284 KB Output is correct
12 Correct 44 ms 86344 KB Output is correct
13 Correct 46 ms 86328 KB Output is correct
14 Correct 43 ms 86348 KB Output is correct
15 Correct 43 ms 86356 KB Output is correct
16 Correct 44 ms 86368 KB Output is correct
17 Correct 47 ms 86336 KB Output is correct
18 Correct 43 ms 86220 KB Output is correct
19 Correct 42 ms 86296 KB Output is correct
20 Correct 43 ms 86236 KB Output is correct
21 Correct 44 ms 86448 KB Output is correct
22 Correct 44 ms 86384 KB Output is correct
23 Correct 43 ms 86340 KB Output is correct
24 Correct 46 ms 86340 KB Output is correct
25 Correct 43 ms 86300 KB Output is correct
26 Correct 43 ms 86360 KB Output is correct
27 Correct 43 ms 86324 KB Output is correct
28 Correct 43 ms 86288 KB Output is correct
29 Correct 44 ms 86428 KB Output is correct
30 Correct 48 ms 86368 KB Output is correct
31 Correct 49 ms 86288 KB Output is correct
32 Correct 48 ms 86316 KB Output is correct
33 Correct 42 ms 86360 KB Output is correct
34 Correct 44 ms 86248 KB Output is correct
35 Correct 43 ms 86220 KB Output is correct
36 Correct 42 ms 86344 KB Output is correct
37 Correct 45 ms 86352 KB Output is correct
38 Correct 43 ms 86348 KB Output is correct
39 Correct 43 ms 86304 KB Output is correct
40 Correct 63 ms 86508 KB Output is correct
41 Correct 405 ms 89620 KB Output is correct
42 Correct 328 ms 87368 KB Output is correct
43 Correct 312 ms 87316 KB Output is correct
44 Correct 342 ms 87444 KB Output is correct
45 Correct 291 ms 87376 KB Output is correct
46 Correct 289 ms 87368 KB Output is correct
47 Correct 325 ms 88124 KB Output is correct
48 Correct 292 ms 87348 KB Output is correct
49 Correct 288 ms 87396 KB Output is correct
50 Correct 301 ms 87412 KB Output is correct
51 Correct 325 ms 88172 KB Output is correct
52 Correct 334 ms 88128 KB Output is correct
53 Correct 269 ms 87320 KB Output is correct
54 Incorrect 36 ms 85972 KB Output isn't correct
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 86224 KB Output is correct
2 Correct 43 ms 86224 KB Output is correct
3 Correct 42 ms 86236 KB Output is correct
4 Correct 42 ms 86348 KB Output is correct
5 Correct 44 ms 86352 KB Output is correct
6 Correct 42 ms 86348 KB Output is correct
7 Correct 41 ms 86308 KB Output is correct
8 Correct 44 ms 86216 KB Output is correct
9 Correct 43 ms 86296 KB Output is correct
10 Correct 42 ms 86336 KB Output is correct
11 Correct 42 ms 86344 KB Output is correct
12 Correct 43 ms 86328 KB Output is correct
13 Correct 44 ms 86100 KB Output is correct
14 Correct 43 ms 85912 KB Output is correct
15 Correct 44 ms 85908 KB Output is correct
16 Correct 48 ms 86020 KB Output is correct
17 Correct 49 ms 85972 KB Output is correct
18 Correct 49 ms 85940 KB Output is correct
19 Correct 51 ms 85956 KB Output is correct
20 Correct 43 ms 86360 KB Output is correct
21 Correct 42 ms 86220 KB Output is correct
22 Correct 43 ms 86220 KB Output is correct
23 Correct 43 ms 86224 KB Output is correct
24 Correct 42 ms 86344 KB Output is correct
25 Correct 43 ms 86264 KB Output is correct
26 Correct 44 ms 86340 KB Output is correct
27 Correct 42 ms 86328 KB Output is correct
28 Correct 50 ms 86284 KB Output is correct
29 Correct 44 ms 86344 KB Output is correct
30 Correct 46 ms 86328 KB Output is correct
31 Correct 43 ms 86348 KB Output is correct
32 Correct 43 ms 86356 KB Output is correct
33 Correct 44 ms 86368 KB Output is correct
34 Correct 47 ms 86336 KB Output is correct
35 Correct 43 ms 86220 KB Output is correct
36 Correct 42 ms 86296 KB Output is correct
37 Correct 43 ms 86236 KB Output is correct
38 Correct 44 ms 86448 KB Output is correct
39 Correct 44 ms 86384 KB Output is correct
40 Correct 43 ms 86340 KB Output is correct
41 Correct 46 ms 86340 KB Output is correct
42 Correct 43 ms 86300 KB Output is correct
43 Correct 43 ms 86360 KB Output is correct
44 Correct 43 ms 86324 KB Output is correct
45 Correct 43 ms 86288 KB Output is correct
46 Correct 44 ms 86428 KB Output is correct
47 Correct 48 ms 86368 KB Output is correct
48 Correct 49 ms 86288 KB Output is correct
49 Correct 48 ms 86316 KB Output is correct
50 Correct 42 ms 86360 KB Output is correct
51 Correct 44 ms 86248 KB Output is correct
52 Correct 43 ms 86220 KB Output is correct
53 Correct 42 ms 86344 KB Output is correct
54 Correct 45 ms 86352 KB Output is correct
55 Correct 43 ms 86348 KB Output is correct
56 Correct 43 ms 86304 KB Output is correct
57 Correct 63 ms 86508 KB Output is correct
58 Correct 405 ms 89620 KB Output is correct
59 Correct 328 ms 87368 KB Output is correct
60 Correct 312 ms 87316 KB Output is correct
61 Correct 342 ms 87444 KB Output is correct
62 Correct 291 ms 87376 KB Output is correct
63 Correct 289 ms 87368 KB Output is correct
64 Correct 325 ms 88124 KB Output is correct
65 Correct 292 ms 87348 KB Output is correct
66 Correct 288 ms 87396 KB Output is correct
67 Correct 301 ms 87412 KB Output is correct
68 Correct 325 ms 88172 KB Output is correct
69 Correct 334 ms 88128 KB Output is correct
70 Correct 269 ms 87320 KB Output is correct
71 Incorrect 36 ms 85972 KB Output isn't correct
72 Halted 0 ms 0 KB -