답안 #733785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733785 2023-05-01T10:06:45 Z myrcella Copy and Paste 3 (JOI22_copypaste3) C++17
25 / 100
418 ms 174564 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];
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;
	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 46 ms 86220 KB Output is correct
2 Correct 44 ms 86328 KB Output is correct
3 Correct 43 ms 86292 KB Output is correct
4 Correct 47 ms 86332 KB Output is correct
5 Correct 43 ms 86240 KB Output is correct
6 Correct 43 ms 86220 KB Output is correct
7 Correct 47 ms 86248 KB Output is correct
8 Correct 45 ms 86336 KB Output is correct
9 Correct 44 ms 86236 KB Output is correct
10 Correct 42 ms 86216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 86236 KB Output is correct
2 Correct 44 ms 86340 KB Output is correct
3 Runtime error 335 ms 174564 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 86220 KB Output is correct
2 Correct 44 ms 86328 KB Output is correct
3 Correct 43 ms 86292 KB Output is correct
4 Correct 47 ms 86332 KB Output is correct
5 Correct 43 ms 86240 KB Output is correct
6 Correct 43 ms 86220 KB Output is correct
7 Correct 47 ms 86248 KB Output is correct
8 Correct 45 ms 86336 KB Output is correct
9 Correct 44 ms 86236 KB Output is correct
10 Correct 42 ms 86216 KB Output is correct
11 Correct 44 ms 86236 KB Output is correct
12 Correct 51 ms 86264 KB Output is correct
13 Correct 45 ms 86344 KB Output is correct
14 Correct 50 ms 86340 KB Output is correct
15 Correct 49 ms 86384 KB Output is correct
16 Correct 43 ms 86332 KB Output is correct
17 Correct 45 ms 86332 KB Output is correct
18 Correct 45 ms 86272 KB Output is correct
19 Correct 46 ms 86404 KB Output is correct
20 Correct 47 ms 86348 KB Output is correct
21 Correct 46 ms 86520 KB Output is correct
22 Correct 46 ms 86348 KB Output is correct
23 Correct 44 ms 86392 KB Output is correct
24 Correct 45 ms 86284 KB Output is correct
25 Correct 46 ms 86344 KB Output is correct
26 Correct 46 ms 86316 KB Output is correct
27 Correct 43 ms 86292 KB Output is correct
28 Correct 46 ms 86324 KB Output is correct
29 Correct 53 ms 86308 KB Output is correct
30 Correct 46 ms 86320 KB Output is correct
31 Correct 47 ms 86360 KB Output is correct
32 Correct 50 ms 86364 KB Output is correct
33 Correct 44 ms 86348 KB Output is correct
34 Correct 45 ms 86336 KB Output is correct
35 Correct 47 ms 86340 KB Output is correct
36 Correct 45 ms 86220 KB Output is correct
37 Correct 44 ms 86296 KB Output is correct
38 Correct 45 ms 86356 KB Output is correct
39 Correct 44 ms 86360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 86220 KB Output is correct
2 Correct 44 ms 86328 KB Output is correct
3 Correct 43 ms 86292 KB Output is correct
4 Correct 47 ms 86332 KB Output is correct
5 Correct 43 ms 86240 KB Output is correct
6 Correct 43 ms 86220 KB Output is correct
7 Correct 47 ms 86248 KB Output is correct
8 Correct 45 ms 86336 KB Output is correct
9 Correct 44 ms 86236 KB Output is correct
10 Correct 42 ms 86216 KB Output is correct
11 Correct 44 ms 86236 KB Output is correct
12 Correct 51 ms 86264 KB Output is correct
13 Correct 45 ms 86344 KB Output is correct
14 Correct 50 ms 86340 KB Output is correct
15 Correct 49 ms 86384 KB Output is correct
16 Correct 43 ms 86332 KB Output is correct
17 Correct 45 ms 86332 KB Output is correct
18 Correct 45 ms 86272 KB Output is correct
19 Correct 46 ms 86404 KB Output is correct
20 Correct 47 ms 86348 KB Output is correct
21 Correct 46 ms 86520 KB Output is correct
22 Correct 46 ms 86348 KB Output is correct
23 Correct 44 ms 86392 KB Output is correct
24 Correct 45 ms 86284 KB Output is correct
25 Correct 46 ms 86344 KB Output is correct
26 Correct 46 ms 86316 KB Output is correct
27 Correct 43 ms 86292 KB Output is correct
28 Correct 46 ms 86324 KB Output is correct
29 Correct 53 ms 86308 KB Output is correct
30 Correct 46 ms 86320 KB Output is correct
31 Correct 47 ms 86360 KB Output is correct
32 Correct 50 ms 86364 KB Output is correct
33 Correct 44 ms 86348 KB Output is correct
34 Correct 45 ms 86336 KB Output is correct
35 Correct 47 ms 86340 KB Output is correct
36 Correct 45 ms 86220 KB Output is correct
37 Correct 44 ms 86296 KB Output is correct
38 Correct 45 ms 86356 KB Output is correct
39 Correct 44 ms 86360 KB Output is correct
40 Correct 62 ms 86528 KB Output is correct
41 Correct 418 ms 89720 KB Output is correct
42 Correct 363 ms 87368 KB Output is correct
43 Correct 296 ms 87420 KB Output is correct
44 Correct 312 ms 87368 KB Output is correct
45 Correct 289 ms 87368 KB Output is correct
46 Correct 322 ms 87540 KB Output is correct
47 Correct 301 ms 88112 KB Output is correct
48 Correct 298 ms 87416 KB Output is correct
49 Correct 312 ms 87368 KB Output is correct
50 Correct 313 ms 87368 KB Output is correct
51 Correct 362 ms 88164 KB Output is correct
52 Correct 366 ms 88100 KB Output is correct
53 Correct 281 ms 87424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 86220 KB Output is correct
2 Correct 44 ms 86328 KB Output is correct
3 Correct 43 ms 86292 KB Output is correct
4 Correct 47 ms 86332 KB Output is correct
5 Correct 43 ms 86240 KB Output is correct
6 Correct 43 ms 86220 KB Output is correct
7 Correct 47 ms 86248 KB Output is correct
8 Correct 45 ms 86336 KB Output is correct
9 Correct 44 ms 86236 KB Output is correct
10 Correct 42 ms 86216 KB Output is correct
11 Correct 44 ms 86236 KB Output is correct
12 Correct 51 ms 86264 KB Output is correct
13 Correct 45 ms 86344 KB Output is correct
14 Correct 50 ms 86340 KB Output is correct
15 Correct 49 ms 86384 KB Output is correct
16 Correct 43 ms 86332 KB Output is correct
17 Correct 45 ms 86332 KB Output is correct
18 Correct 45 ms 86272 KB Output is correct
19 Correct 46 ms 86404 KB Output is correct
20 Correct 47 ms 86348 KB Output is correct
21 Correct 46 ms 86520 KB Output is correct
22 Correct 46 ms 86348 KB Output is correct
23 Correct 44 ms 86392 KB Output is correct
24 Correct 45 ms 86284 KB Output is correct
25 Correct 46 ms 86344 KB Output is correct
26 Correct 46 ms 86316 KB Output is correct
27 Correct 43 ms 86292 KB Output is correct
28 Correct 46 ms 86324 KB Output is correct
29 Correct 53 ms 86308 KB Output is correct
30 Correct 46 ms 86320 KB Output is correct
31 Correct 47 ms 86360 KB Output is correct
32 Correct 50 ms 86364 KB Output is correct
33 Correct 44 ms 86348 KB Output is correct
34 Correct 45 ms 86336 KB Output is correct
35 Correct 47 ms 86340 KB Output is correct
36 Correct 45 ms 86220 KB Output is correct
37 Correct 44 ms 86296 KB Output is correct
38 Correct 45 ms 86356 KB Output is correct
39 Correct 44 ms 86360 KB Output is correct
40 Correct 62 ms 86528 KB Output is correct
41 Correct 418 ms 89720 KB Output is correct
42 Correct 363 ms 87368 KB Output is correct
43 Correct 296 ms 87420 KB Output is correct
44 Correct 312 ms 87368 KB Output is correct
45 Correct 289 ms 87368 KB Output is correct
46 Correct 322 ms 87540 KB Output is correct
47 Correct 301 ms 88112 KB Output is correct
48 Correct 298 ms 87416 KB Output is correct
49 Correct 312 ms 87368 KB Output is correct
50 Correct 313 ms 87368 KB Output is correct
51 Correct 362 ms 88164 KB Output is correct
52 Correct 366 ms 88100 KB Output is correct
53 Correct 281 ms 87424 KB Output is correct
54 Runtime error 115 ms 174376 KB Execution killed with signal 11
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 86220 KB Output is correct
2 Correct 44 ms 86328 KB Output is correct
3 Correct 43 ms 86292 KB Output is correct
4 Correct 47 ms 86332 KB Output is correct
5 Correct 43 ms 86240 KB Output is correct
6 Correct 43 ms 86220 KB Output is correct
7 Correct 47 ms 86248 KB Output is correct
8 Correct 45 ms 86336 KB Output is correct
9 Correct 44 ms 86236 KB Output is correct
10 Correct 42 ms 86216 KB Output is correct
11 Correct 43 ms 86236 KB Output is correct
12 Correct 44 ms 86340 KB Output is correct
13 Runtime error 335 ms 174564 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -