답안 #734112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734112 2023-05-01T17:24:28 Z myrcella Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
768 ms 148608 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 = 2555;

int n;
ll A,B,C;
string s;
int a[maxn];
int len[maxn][maxn];
int nxt[maxn][maxn];
ll f[maxn][maxn],g[maxn][maxn];

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie(0);
	memset(f,inf,sizeof(f));
	memset(g,inf,sizeof(g));
	cin>>n>>s>>A>>B>>C;
	rep(i,0,n) a[i] = (int)(s[i]-'a');
	rep(i,1,n) {
		vector <int> tmp;	
		for (int j = 0;i+j<n;j++) {
			if (a[j]!=a[j+i]) {
				int cnt = 0;
				while (!tmp.empty()) {
					cnt++;
					len[tmp.back()][tmp.back()+i] = cnt;
					tmp.pop_back();
				}
			}
			else tmp.pb(j);
		}
		int cnt = 0;
		while (!tmp.empty()) {
			cnt++;
			len[tmp.back()][tmp.back()+i] = cnt;
			tmp.pop_back();
		}
	}
	memset(nxt,-1,sizeof(nxt));
	rep(i,0,n) {
		pq <pii,vector<pii>,greater<pii>> q;
		rep(j,i+1,n) {
			q.push({j,len[i][j]});
		}
		rep(j,i,n) {
			while (!q.empty() and (q.top().se<j-i+1 or q.top().fi<=j)) q.pop();
			if (!q.empty()) nxt[i][j] = q.top().fi;
//			cout<<i<<" "<<j<<" "<<nxt[i][j]<<endl;
		}
	}
	rep(k,0,n) {
		for (int i = 0;i+k<n;i++) {
			int j = i+k;
			f[i][j] = min(f[i][j],(j-i+1)*A);
			f[i][j+1] = min(f[i][j+1],f[i][j]+A);
			g[i][j] = min(g[i][j],f[i][j]+B);
			if (i>=1) g[i-1][j] = min(g[i-1][j],g[i][j]+A);
			int curi=i;
			ll sum = g[i][j] + C;
			while (nxt[curi][curi+j-i]!=-1) {
				int tmp = nxt[curi][curi+j-i];
				sum += A*(tmp - (curi+j-i) - 1) + C;
				f[i][tmp+j-i] = min(f[i][tmp+j-i],sum);
				curi = tmp;
			}
		}
	}
	ll ans = f[0][n-1];
	rep(i,1,n) ans = min(ans,A*i+f[i][n-1]);
	cout<<ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 128056 KB Output is correct
2 Correct 48 ms 128036 KB Output is correct
3 Correct 56 ms 127972 KB Output is correct
4 Correct 50 ms 128032 KB Output is correct
5 Correct 48 ms 127968 KB Output is correct
6 Correct 50 ms 128068 KB Output is correct
7 Correct 48 ms 127952 KB Output is correct
8 Correct 48 ms 128056 KB Output is correct
9 Correct 50 ms 127948 KB Output is correct
10 Correct 52 ms 128048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 128048 KB Output is correct
2 Correct 50 ms 127972 KB Output is correct
3 Correct 390 ms 141760 KB Output is correct
4 Correct 468 ms 143340 KB Output is correct
5 Correct 533 ms 144832 KB Output is correct
6 Correct 648 ms 146656 KB Output is correct
7 Correct 602 ms 148536 KB Output is correct
8 Correct 768 ms 148536 KB Output is correct
9 Correct 767 ms 148608 KB Output is correct
10 Correct 47 ms 127988 KB Output is correct
11 Correct 49 ms 128084 KB Output is correct
12 Correct 47 ms 128008 KB Output is correct
13 Correct 52 ms 128052 KB Output is correct
14 Correct 51 ms 128004 KB Output is correct
15 Correct 47 ms 128004 KB Output is correct
16 Correct 47 ms 128108 KB Output is correct
17 Correct 50 ms 127948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 128056 KB Output is correct
2 Correct 48 ms 128036 KB Output is correct
3 Correct 56 ms 127972 KB Output is correct
4 Correct 50 ms 128032 KB Output is correct
5 Correct 48 ms 127968 KB Output is correct
6 Correct 50 ms 128068 KB Output is correct
7 Correct 48 ms 127952 KB Output is correct
8 Correct 48 ms 128056 KB Output is correct
9 Correct 50 ms 127948 KB Output is correct
10 Correct 52 ms 128048 KB Output is correct
11 Correct 51 ms 128076 KB Output is correct
12 Correct 47 ms 128032 KB Output is correct
13 Correct 49 ms 128104 KB Output is correct
14 Correct 48 ms 128028 KB Output is correct
15 Correct 48 ms 128084 KB Output is correct
16 Correct 49 ms 128180 KB Output is correct
17 Correct 48 ms 127984 KB Output is correct
18 Correct 48 ms 127948 KB Output is correct
19 Correct 46 ms 128056 KB Output is correct
20 Correct 49 ms 127996 KB Output is correct
21 Correct 47 ms 128076 KB Output is correct
22 Correct 50 ms 128148 KB Output is correct
23 Correct 46 ms 128140 KB Output is correct
24 Correct 48 ms 128128 KB Output is correct
25 Correct 48 ms 128036 KB Output is correct
26 Correct 47 ms 128056 KB Output is correct
27 Correct 47 ms 128124 KB Output is correct
28 Correct 49 ms 128096 KB Output is correct
29 Correct 49 ms 128076 KB Output is correct
30 Correct 50 ms 128168 KB Output is correct
31 Correct 48 ms 128108 KB Output is correct
32 Correct 48 ms 128084 KB Output is correct
33 Correct 50 ms 128020 KB Output is correct
34 Correct 47 ms 127948 KB Output is correct
35 Correct 55 ms 128052 KB Output is correct
36 Correct 51 ms 127948 KB Output is correct
37 Correct 50 ms 128004 KB Output is correct
38 Correct 57 ms 128048 KB Output is correct
39 Correct 48 ms 128076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 128056 KB Output is correct
2 Correct 48 ms 128036 KB Output is correct
3 Correct 56 ms 127972 KB Output is correct
4 Correct 50 ms 128032 KB Output is correct
5 Correct 48 ms 127968 KB Output is correct
6 Correct 50 ms 128068 KB Output is correct
7 Correct 48 ms 127952 KB Output is correct
8 Correct 48 ms 128056 KB Output is correct
9 Correct 50 ms 127948 KB Output is correct
10 Correct 52 ms 128048 KB Output is correct
11 Correct 51 ms 128076 KB Output is correct
12 Correct 47 ms 128032 KB Output is correct
13 Correct 49 ms 128104 KB Output is correct
14 Correct 48 ms 128028 KB Output is correct
15 Correct 48 ms 128084 KB Output is correct
16 Correct 49 ms 128180 KB Output is correct
17 Correct 48 ms 127984 KB Output is correct
18 Correct 48 ms 127948 KB Output is correct
19 Correct 46 ms 128056 KB Output is correct
20 Correct 49 ms 127996 KB Output is correct
21 Correct 47 ms 128076 KB Output is correct
22 Correct 50 ms 128148 KB Output is correct
23 Correct 46 ms 128140 KB Output is correct
24 Correct 48 ms 128128 KB Output is correct
25 Correct 48 ms 128036 KB Output is correct
26 Correct 47 ms 128056 KB Output is correct
27 Correct 47 ms 128124 KB Output is correct
28 Correct 49 ms 128096 KB Output is correct
29 Correct 49 ms 128076 KB Output is correct
30 Correct 50 ms 128168 KB Output is correct
31 Correct 48 ms 128108 KB Output is correct
32 Correct 48 ms 128084 KB Output is correct
33 Correct 50 ms 128020 KB Output is correct
34 Correct 47 ms 127948 KB Output is correct
35 Correct 55 ms 128052 KB Output is correct
36 Correct 51 ms 127948 KB Output is correct
37 Correct 50 ms 128004 KB Output is correct
38 Correct 57 ms 128048 KB Output is correct
39 Correct 48 ms 128076 KB Output is correct
40 Correct 49 ms 128336 KB Output is correct
41 Correct 50 ms 128972 KB Output is correct
42 Correct 54 ms 128860 KB Output is correct
43 Correct 54 ms 128960 KB Output is correct
44 Correct 56 ms 128892 KB Output is correct
45 Correct 51 ms 128916 KB Output is correct
46 Correct 50 ms 128800 KB Output is correct
47 Correct 52 ms 128888 KB Output is correct
48 Correct 51 ms 128760 KB Output is correct
49 Correct 53 ms 128804 KB Output is correct
50 Correct 52 ms 128820 KB Output is correct
51 Correct 53 ms 128880 KB Output is correct
52 Correct 51 ms 128844 KB Output is correct
53 Correct 50 ms 128748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 128056 KB Output is correct
2 Correct 48 ms 128036 KB Output is correct
3 Correct 56 ms 127972 KB Output is correct
4 Correct 50 ms 128032 KB Output is correct
5 Correct 48 ms 127968 KB Output is correct
6 Correct 50 ms 128068 KB Output is correct
7 Correct 48 ms 127952 KB Output is correct
8 Correct 48 ms 128056 KB Output is correct
9 Correct 50 ms 127948 KB Output is correct
10 Correct 52 ms 128048 KB Output is correct
11 Correct 51 ms 128076 KB Output is correct
12 Correct 47 ms 128032 KB Output is correct
13 Correct 49 ms 128104 KB Output is correct
14 Correct 48 ms 128028 KB Output is correct
15 Correct 48 ms 128084 KB Output is correct
16 Correct 49 ms 128180 KB Output is correct
17 Correct 48 ms 127984 KB Output is correct
18 Correct 48 ms 127948 KB Output is correct
19 Correct 46 ms 128056 KB Output is correct
20 Correct 49 ms 127996 KB Output is correct
21 Correct 47 ms 128076 KB Output is correct
22 Correct 50 ms 128148 KB Output is correct
23 Correct 46 ms 128140 KB Output is correct
24 Correct 48 ms 128128 KB Output is correct
25 Correct 48 ms 128036 KB Output is correct
26 Correct 47 ms 128056 KB Output is correct
27 Correct 47 ms 128124 KB Output is correct
28 Correct 49 ms 128096 KB Output is correct
29 Correct 49 ms 128076 KB Output is correct
30 Correct 50 ms 128168 KB Output is correct
31 Correct 48 ms 128108 KB Output is correct
32 Correct 48 ms 128084 KB Output is correct
33 Correct 50 ms 128020 KB Output is correct
34 Correct 47 ms 127948 KB Output is correct
35 Correct 55 ms 128052 KB Output is correct
36 Correct 51 ms 127948 KB Output is correct
37 Correct 50 ms 128004 KB Output is correct
38 Correct 57 ms 128048 KB Output is correct
39 Correct 48 ms 128076 KB Output is correct
40 Correct 49 ms 128336 KB Output is correct
41 Correct 50 ms 128972 KB Output is correct
42 Correct 54 ms 128860 KB Output is correct
43 Correct 54 ms 128960 KB Output is correct
44 Correct 56 ms 128892 KB Output is correct
45 Correct 51 ms 128916 KB Output is correct
46 Correct 50 ms 128800 KB Output is correct
47 Correct 52 ms 128888 KB Output is correct
48 Correct 51 ms 128760 KB Output is correct
49 Correct 53 ms 128804 KB Output is correct
50 Correct 52 ms 128820 KB Output is correct
51 Correct 53 ms 128880 KB Output is correct
52 Correct 51 ms 128844 KB Output is correct
53 Correct 50 ms 128748 KB Output is correct
54 Correct 56 ms 130184 KB Output is correct
55 Correct 134 ms 134016 KB Output is correct
56 Correct 103 ms 133964 KB Output is correct
57 Correct 94 ms 134028 KB Output is correct
58 Correct 92 ms 133964 KB Output is correct
59 Correct 93 ms 133924 KB Output is correct
60 Correct 91 ms 133772 KB Output is correct
61 Correct 98 ms 133720 KB Output is correct
62 Correct 115 ms 134028 KB Output is correct
63 Correct 94 ms 133744 KB Output is correct
64 Correct 97 ms 133816 KB Output is correct
65 Correct 106 ms 133964 KB Output is correct
66 Correct 105 ms 133868 KB Output is correct
67 Correct 92 ms 133664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 128056 KB Output is correct
2 Correct 48 ms 128036 KB Output is correct
3 Correct 56 ms 127972 KB Output is correct
4 Correct 50 ms 128032 KB Output is correct
5 Correct 48 ms 127968 KB Output is correct
6 Correct 50 ms 128068 KB Output is correct
7 Correct 48 ms 127952 KB Output is correct
8 Correct 48 ms 128056 KB Output is correct
9 Correct 50 ms 127948 KB Output is correct
10 Correct 52 ms 128048 KB Output is correct
11 Correct 48 ms 128048 KB Output is correct
12 Correct 50 ms 127972 KB Output is correct
13 Correct 390 ms 141760 KB Output is correct
14 Correct 468 ms 143340 KB Output is correct
15 Correct 533 ms 144832 KB Output is correct
16 Correct 648 ms 146656 KB Output is correct
17 Correct 602 ms 148536 KB Output is correct
18 Correct 768 ms 148536 KB Output is correct
19 Correct 767 ms 148608 KB Output is correct
20 Correct 47 ms 127988 KB Output is correct
21 Correct 49 ms 128084 KB Output is correct
22 Correct 47 ms 128008 KB Output is correct
23 Correct 52 ms 128052 KB Output is correct
24 Correct 51 ms 128004 KB Output is correct
25 Correct 47 ms 128004 KB Output is correct
26 Correct 47 ms 128108 KB Output is correct
27 Correct 50 ms 127948 KB Output is correct
28 Correct 51 ms 128076 KB Output is correct
29 Correct 47 ms 128032 KB Output is correct
30 Correct 49 ms 128104 KB Output is correct
31 Correct 48 ms 128028 KB Output is correct
32 Correct 48 ms 128084 KB Output is correct
33 Correct 49 ms 128180 KB Output is correct
34 Correct 48 ms 127984 KB Output is correct
35 Correct 48 ms 127948 KB Output is correct
36 Correct 46 ms 128056 KB Output is correct
37 Correct 49 ms 127996 KB Output is correct
38 Correct 47 ms 128076 KB Output is correct
39 Correct 50 ms 128148 KB Output is correct
40 Correct 46 ms 128140 KB Output is correct
41 Correct 48 ms 128128 KB Output is correct
42 Correct 48 ms 128036 KB Output is correct
43 Correct 47 ms 128056 KB Output is correct
44 Correct 47 ms 128124 KB Output is correct
45 Correct 49 ms 128096 KB Output is correct
46 Correct 49 ms 128076 KB Output is correct
47 Correct 50 ms 128168 KB Output is correct
48 Correct 48 ms 128108 KB Output is correct
49 Correct 48 ms 128084 KB Output is correct
50 Correct 50 ms 128020 KB Output is correct
51 Correct 47 ms 127948 KB Output is correct
52 Correct 55 ms 128052 KB Output is correct
53 Correct 51 ms 127948 KB Output is correct
54 Correct 50 ms 128004 KB Output is correct
55 Correct 57 ms 128048 KB Output is correct
56 Correct 48 ms 128076 KB Output is correct
57 Correct 49 ms 128336 KB Output is correct
58 Correct 50 ms 128972 KB Output is correct
59 Correct 54 ms 128860 KB Output is correct
60 Correct 54 ms 128960 KB Output is correct
61 Correct 56 ms 128892 KB Output is correct
62 Correct 51 ms 128916 KB Output is correct
63 Correct 50 ms 128800 KB Output is correct
64 Correct 52 ms 128888 KB Output is correct
65 Correct 51 ms 128760 KB Output is correct
66 Correct 53 ms 128804 KB Output is correct
67 Correct 52 ms 128820 KB Output is correct
68 Correct 53 ms 128880 KB Output is correct
69 Correct 51 ms 128844 KB Output is correct
70 Correct 50 ms 128748 KB Output is correct
71 Correct 56 ms 130184 KB Output is correct
72 Correct 134 ms 134016 KB Output is correct
73 Correct 103 ms 133964 KB Output is correct
74 Correct 94 ms 134028 KB Output is correct
75 Correct 92 ms 133964 KB Output is correct
76 Correct 93 ms 133924 KB Output is correct
77 Correct 91 ms 133772 KB Output is correct
78 Correct 98 ms 133720 KB Output is correct
79 Correct 115 ms 134028 KB Output is correct
80 Correct 94 ms 133744 KB Output is correct
81 Correct 97 ms 133816 KB Output is correct
82 Correct 106 ms 133964 KB Output is correct
83 Correct 105 ms 133868 KB Output is correct
84 Correct 92 ms 133664 KB Output is correct
85 Correct 179 ms 139208 KB Output is correct
86 Correct 400 ms 148516 KB Output is correct
87 Correct 366 ms 148428 KB Output is correct
88 Correct 342 ms 148556 KB Output is correct
89 Correct 328 ms 148428 KB Output is correct
90 Correct 325 ms 148068 KB Output is correct
91 Correct 505 ms 148248 KB Output is correct
92 Correct 615 ms 148408 KB Output is correct
93 Correct 369 ms 148124 KB Output is correct
94 Correct 376 ms 148100 KB Output is correct
95 Correct 533 ms 148560 KB Output is correct
96 Correct 466 ms 148428 KB Output is correct
97 Correct 329 ms 148204 KB Output is correct