Submission #1076612

# Submission time Handle Problem Language Result Execution time Memory
1076612 2024-08-26T15:00:10 Z coldbr3w Copy and Paste 3 (JOI22_copypaste3) C++17
57 / 100
3000 ms 558432 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second  
#define all(x) (x).begin(), (x).end()

const ll N = 3000;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll n,a,b,c;
string s;
vector<int> z_function(string s) {
    int n = s.length();
    vector<int> z(n);
    int l = 0, r = 0;
    for (int i = 0; i < n; ++i) {
        if (i <= r) z[i] = min(r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
        if (i + z[i] - 1 > r) {
            l = i;
            r = i + z[i] - 1;
        } 
    }
    return z;
}
struct ccjv{int l,r,cnt;};
int st[N][12];
ll dp[N][N], lg[N];
vector<ccjv>adj[N][N];
int get(int l, int r){
	int p = lg[r - l + 1];
	return max(st[l][p], st[r - (1 << p) + 1][p]);
}
void to_thic_cau(){ 
	cin >> n >> s >> a >> b >> c;
	s = " " + s;
	for(int i = 1; i <= n;i++) lg[i] = __lg(i);
	for(int i = 1; i <= n;i++){
		for(int j = i; j <= n;j++) dp[i][j] = 1ll * (j - i + 1) * a;
	}
	for(int i = 1; i <= n;i++){
		string t;
		for(int j = i; j <= n;j++) t += s[j];
		vector<int>z = z_function(t);
		int sz = (ll)t.size() - 1;
		for(int i = 0; i <= sz;i++) st[i][0] = z[i];
		for(int j = 1; j <= 11;j++){
			for(int i = 0; i + (1 << j) <= sz + 1;i++) st[i][j] = max(st[i][j-1], st[i + (1 << (j - 1))][j - 1]);
		}
		ll mx = get(0, sz);
		for(int len = 1; len <= mx;len++){
			int cnt = 0, idx = -1, fir = -1;
			while(1){
				int l = idx + 1, r = sz, pos = -1;
				while(l <= r){
					int mid = (l + r) / 2;
					if(get(idx + 1, mid) >= len) pos = mid, r = mid - 1;
					else l = mid + 1;
				}
				if(pos == -1) break;
				if(fir == -1) fir = pos;
				idx = pos + len - 1, cnt++;
				adj[fir + i][idx + i].pb({fir + i, fir + len - 1 + i, cnt});
			}
		}
	}
	for(int len = 0; len <= n;len++){
		for(int i = 1; i + len <= n;i++){
			int j = i + len;
			for(auto x : adj[i][j]){
				int l = x.l, r = x.r, cnt = x.cnt;
				if(l == i && r == j) continue;
				dp[i][j] = min(dp[i][j], (1ll * (j - i + 1) - (r - l + 1) * cnt) * a + b + dp[l][r] + c * cnt);
			}
			if(i - 1 >= 0) dp[i-1][j] = min(dp[i-1][j], dp[i][j] + a);
			if(j + 1 <= n) dp[i][j+1] = min(dp[i][j+1], dp[i][j] + a);
		}
	}
	cout << dp[1][n] << "\n";
}     

signed main()   
{  
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll tc = 1;
	//cin >> tc;
	while(tc--) to_thic_cau();
}
# Verdict Execution time Memory Grader output
1 Correct 86 ms 211676 KB Output is correct
2 Correct 87 ms 211768 KB Output is correct
3 Correct 85 ms 211776 KB Output is correct
4 Correct 84 ms 211696 KB Output is correct
5 Correct 98 ms 211672 KB Output is correct
6 Correct 92 ms 211792 KB Output is correct
7 Correct 89 ms 211796 KB Output is correct
8 Correct 80 ms 211588 KB Output is correct
9 Correct 89 ms 211804 KB Output is correct
10 Correct 98 ms 211604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 211684 KB Output is correct
2 Correct 113 ms 211716 KB Output is correct
3 Correct 1867 ms 424372 KB Output is correct
4 Correct 2427 ms 462032 KB Output is correct
5 Correct 2983 ms 506504 KB Output is correct
6 Execution timed out 3060 ms 558432 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 211676 KB Output is correct
2 Correct 87 ms 211768 KB Output is correct
3 Correct 85 ms 211776 KB Output is correct
4 Correct 84 ms 211696 KB Output is correct
5 Correct 98 ms 211672 KB Output is correct
6 Correct 92 ms 211792 KB Output is correct
7 Correct 89 ms 211796 KB Output is correct
8 Correct 80 ms 211588 KB Output is correct
9 Correct 89 ms 211804 KB Output is correct
10 Correct 98 ms 211604 KB Output is correct
11 Correct 88 ms 211812 KB Output is correct
12 Correct 86 ms 211640 KB Output is correct
13 Correct 94 ms 211792 KB Output is correct
14 Correct 106 ms 211792 KB Output is correct
15 Correct 88 ms 211792 KB Output is correct
16 Correct 97 ms 211788 KB Output is correct
17 Correct 90 ms 211796 KB Output is correct
18 Correct 86 ms 211796 KB Output is correct
19 Correct 85 ms 211796 KB Output is correct
20 Correct 85 ms 211748 KB Output is correct
21 Correct 82 ms 211800 KB Output is correct
22 Correct 83 ms 211932 KB Output is correct
23 Correct 85 ms 211792 KB Output is correct
24 Correct 86 ms 211736 KB Output is correct
25 Correct 90 ms 211872 KB Output is correct
26 Correct 89 ms 212052 KB Output is correct
27 Correct 86 ms 211716 KB Output is correct
28 Correct 82 ms 211796 KB Output is correct
29 Correct 77 ms 211792 KB Output is correct
30 Correct 118 ms 211792 KB Output is correct
31 Correct 104 ms 211792 KB Output is correct
32 Correct 75 ms 211792 KB Output is correct
33 Correct 75 ms 211792 KB Output is correct
34 Correct 75 ms 211736 KB Output is correct
35 Correct 86 ms 212048 KB Output is correct
36 Correct 86 ms 211788 KB Output is correct
37 Correct 84 ms 211796 KB Output is correct
38 Correct 81 ms 211860 KB Output is correct
39 Correct 108 ms 211900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 211676 KB Output is correct
2 Correct 87 ms 211768 KB Output is correct
3 Correct 85 ms 211776 KB Output is correct
4 Correct 84 ms 211696 KB Output is correct
5 Correct 98 ms 211672 KB Output is correct
6 Correct 92 ms 211792 KB Output is correct
7 Correct 89 ms 211796 KB Output is correct
8 Correct 80 ms 211588 KB Output is correct
9 Correct 89 ms 211804 KB Output is correct
10 Correct 98 ms 211604 KB Output is correct
11 Correct 88 ms 211812 KB Output is correct
12 Correct 86 ms 211640 KB Output is correct
13 Correct 94 ms 211792 KB Output is correct
14 Correct 106 ms 211792 KB Output is correct
15 Correct 88 ms 211792 KB Output is correct
16 Correct 97 ms 211788 KB Output is correct
17 Correct 90 ms 211796 KB Output is correct
18 Correct 86 ms 211796 KB Output is correct
19 Correct 85 ms 211796 KB Output is correct
20 Correct 85 ms 211748 KB Output is correct
21 Correct 82 ms 211800 KB Output is correct
22 Correct 83 ms 211932 KB Output is correct
23 Correct 85 ms 211792 KB Output is correct
24 Correct 86 ms 211736 KB Output is correct
25 Correct 90 ms 211872 KB Output is correct
26 Correct 89 ms 212052 KB Output is correct
27 Correct 86 ms 211716 KB Output is correct
28 Correct 82 ms 211796 KB Output is correct
29 Correct 77 ms 211792 KB Output is correct
30 Correct 118 ms 211792 KB Output is correct
31 Correct 104 ms 211792 KB Output is correct
32 Correct 75 ms 211792 KB Output is correct
33 Correct 75 ms 211792 KB Output is correct
34 Correct 75 ms 211736 KB Output is correct
35 Correct 86 ms 212048 KB Output is correct
36 Correct 86 ms 211788 KB Output is correct
37 Correct 84 ms 211796 KB Output is correct
38 Correct 81 ms 211860 KB Output is correct
39 Correct 108 ms 211900 KB Output is correct
40 Correct 83 ms 212308 KB Output is correct
41 Correct 105 ms 214232 KB Output is correct
42 Correct 95 ms 213340 KB Output is correct
43 Correct 84 ms 213212 KB Output is correct
44 Correct 101 ms 213320 KB Output is correct
45 Correct 93 ms 213356 KB Output is correct
46 Correct 93 ms 213332 KB Output is correct
47 Correct 91 ms 213372 KB Output is correct
48 Correct 88 ms 213448 KB Output is correct
49 Correct 94 ms 213332 KB Output is correct
50 Correct 98 ms 213432 KB Output is correct
51 Correct 97 ms 213796 KB Output is correct
52 Correct 94 ms 213708 KB Output is correct
53 Correct 94 ms 213420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 211676 KB Output is correct
2 Correct 87 ms 211768 KB Output is correct
3 Correct 85 ms 211776 KB Output is correct
4 Correct 84 ms 211696 KB Output is correct
5 Correct 98 ms 211672 KB Output is correct
6 Correct 92 ms 211792 KB Output is correct
7 Correct 89 ms 211796 KB Output is correct
8 Correct 80 ms 211588 KB Output is correct
9 Correct 89 ms 211804 KB Output is correct
10 Correct 98 ms 211604 KB Output is correct
11 Correct 88 ms 211812 KB Output is correct
12 Correct 86 ms 211640 KB Output is correct
13 Correct 94 ms 211792 KB Output is correct
14 Correct 106 ms 211792 KB Output is correct
15 Correct 88 ms 211792 KB Output is correct
16 Correct 97 ms 211788 KB Output is correct
17 Correct 90 ms 211796 KB Output is correct
18 Correct 86 ms 211796 KB Output is correct
19 Correct 85 ms 211796 KB Output is correct
20 Correct 85 ms 211748 KB Output is correct
21 Correct 82 ms 211800 KB Output is correct
22 Correct 83 ms 211932 KB Output is correct
23 Correct 85 ms 211792 KB Output is correct
24 Correct 86 ms 211736 KB Output is correct
25 Correct 90 ms 211872 KB Output is correct
26 Correct 89 ms 212052 KB Output is correct
27 Correct 86 ms 211716 KB Output is correct
28 Correct 82 ms 211796 KB Output is correct
29 Correct 77 ms 211792 KB Output is correct
30 Correct 118 ms 211792 KB Output is correct
31 Correct 104 ms 211792 KB Output is correct
32 Correct 75 ms 211792 KB Output is correct
33 Correct 75 ms 211792 KB Output is correct
34 Correct 75 ms 211736 KB Output is correct
35 Correct 86 ms 212048 KB Output is correct
36 Correct 86 ms 211788 KB Output is correct
37 Correct 84 ms 211796 KB Output is correct
38 Correct 81 ms 211860 KB Output is correct
39 Correct 108 ms 211900 KB Output is correct
40 Correct 83 ms 212308 KB Output is correct
41 Correct 105 ms 214232 KB Output is correct
42 Correct 95 ms 213340 KB Output is correct
43 Correct 84 ms 213212 KB Output is correct
44 Correct 101 ms 213320 KB Output is correct
45 Correct 93 ms 213356 KB Output is correct
46 Correct 93 ms 213332 KB Output is correct
47 Correct 91 ms 213372 KB Output is correct
48 Correct 88 ms 213448 KB Output is correct
49 Correct 94 ms 213332 KB Output is correct
50 Correct 98 ms 213432 KB Output is correct
51 Correct 97 ms 213796 KB Output is correct
52 Correct 94 ms 213708 KB Output is correct
53 Correct 94 ms 213420 KB Output is correct
54 Correct 112 ms 218020 KB Output is correct
55 Correct 504 ms 272952 KB Output is correct
56 Correct 181 ms 238420 KB Output is correct
57 Correct 184 ms 236188 KB Output is correct
58 Correct 150 ms 235532 KB Output is correct
59 Correct 147 ms 235348 KB Output is correct
60 Correct 137 ms 235344 KB Output is correct
61 Correct 179 ms 236880 KB Output is correct
62 Correct 348 ms 264732 KB Output is correct
63 Correct 162 ms 236368 KB Output is correct
64 Correct 181 ms 238164 KB Output is correct
65 Correct 289 ms 251988 KB Output is correct
66 Correct 275 ms 251840 KB Output is correct
67 Correct 136 ms 235348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 211676 KB Output is correct
2 Correct 87 ms 211768 KB Output is correct
3 Correct 85 ms 211776 KB Output is correct
4 Correct 84 ms 211696 KB Output is correct
5 Correct 98 ms 211672 KB Output is correct
6 Correct 92 ms 211792 KB Output is correct
7 Correct 89 ms 211796 KB Output is correct
8 Correct 80 ms 211588 KB Output is correct
9 Correct 89 ms 211804 KB Output is correct
10 Correct 98 ms 211604 KB Output is correct
11 Correct 101 ms 211684 KB Output is correct
12 Correct 113 ms 211716 KB Output is correct
13 Correct 1867 ms 424372 KB Output is correct
14 Correct 2427 ms 462032 KB Output is correct
15 Correct 2983 ms 506504 KB Output is correct
16 Execution timed out 3060 ms 558432 KB Time limit exceeded
17 Halted 0 ms 0 KB -