Submission #1076550

# Submission time Handle Problem Language Result Execution time Memory
1076550 2024-08-26T14:42:04 Z coldbr3w Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
3000 ms 610028 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<ll> z_function(string s) {
    ll n = s.length();
    vector<ll> z(n);
    ll l = 0, r = 0;
    for (int i = 0; i < n; ++i) {
        if (i <= r) z[i] = min(r - i * 1ll + 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{ll l,r,cnt;};
ll st[N][13], dp[N][N];
vector<ccjv>adj[N][N];
ll get(ll l, ll r){
	ll p = 31 - __builtin_clz(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(ll i = 1; i <= n;i++){
		for(ll j = 1; j <= n;j++) dp[i][j] = (j - i + 1) * a;
	}
	for(int i = 1; i <= n;i++){
		string t;
		for(int j = i; j <= n;j++) t += s[j];
		vector<ll>z = z_function(t);
		ll sz = (ll)t.size() - 1;
		for(int i = 0; i <= sz;i++) st[i][0] = z[i];
		for(int j = 1; j <= 12;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]);
		}
		for(int len = 1; len <= sz;len++){
			ll cnt = 0, idx = -1, fir = -1;
			while(1){
				ll l = idx + 1, r = sz, pos = -1;
				while(l <= r){
					ll 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(ll i = 1; i + len <= n;i++){
			ll j = i + len;
			for(auto x : adj[i][j]){
				ll l = x.l, r = x.r, cnt = x.cnt;
				if(l == i && r == j) continue;
				dp[i][j] = min(dp[i][j], ((j - i + 1) - (r - l + 1) * cnt) * a + b + dp[l][r] + c * cnt);
			}
			for(ll l = i; l <= j;l++){
				for(ll r = l; r <= j;r++){
					if(l == i && r == j) continue;
					dp[i][j] = min(dp[i][j], (l - i + j - r) * a + dp[l][r]);
				}
			}
		}
	}
	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 100 ms 211792 KB Output is correct
2 Correct 76 ms 211668 KB Output is correct
3 Correct 94 ms 211560 KB Output is correct
4 Correct 80 ms 211732 KB Output is correct
5 Correct 97 ms 211808 KB Output is correct
6 Correct 84 ms 211720 KB Output is correct
7 Correct 92 ms 211796 KB Output is correct
8 Correct 107 ms 211616 KB Output is correct
9 Correct 86 ms 211592 KB Output is correct
10 Correct 105 ms 211792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 211860 KB Output is correct
2 Correct 101 ms 211796 KB Output is correct
3 Execution timed out 3105 ms 610028 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 211792 KB Output is correct
2 Correct 76 ms 211668 KB Output is correct
3 Correct 94 ms 211560 KB Output is correct
4 Correct 80 ms 211732 KB Output is correct
5 Correct 97 ms 211808 KB Output is correct
6 Correct 84 ms 211720 KB Output is correct
7 Correct 92 ms 211796 KB Output is correct
8 Correct 107 ms 211616 KB Output is correct
9 Correct 86 ms 211592 KB Output is correct
10 Correct 105 ms 211792 KB Output is correct
11 Correct 84 ms 211700 KB Output is correct
12 Correct 87 ms 211852 KB Output is correct
13 Correct 75 ms 211796 KB Output is correct
14 Correct 86 ms 211680 KB Output is correct
15 Correct 81 ms 211796 KB Output is correct
16 Correct 84 ms 211796 KB Output is correct
17 Correct 82 ms 211756 KB Output is correct
18 Correct 76 ms 211660 KB Output is correct
19 Correct 108 ms 211796 KB Output is correct
20 Correct 74 ms 211796 KB Output is correct
21 Correct 82 ms 211796 KB Output is correct
22 Correct 98 ms 211860 KB Output is correct
23 Correct 73 ms 211772 KB Output is correct
24 Correct 81 ms 211944 KB Output is correct
25 Correct 78 ms 211796 KB Output is correct
26 Correct 99 ms 211792 KB Output is correct
27 Correct 104 ms 211904 KB Output is correct
28 Correct 76 ms 211792 KB Output is correct
29 Correct 93 ms 211792 KB Output is correct
30 Correct 74 ms 211792 KB Output is correct
31 Correct 104 ms 211792 KB Output is correct
32 Correct 73 ms 211796 KB Output is correct
33 Correct 100 ms 211876 KB Output is correct
34 Correct 78 ms 211692 KB Output is correct
35 Correct 76 ms 211792 KB Output is correct
36 Correct 77 ms 211800 KB Output is correct
37 Correct 80 ms 211792 KB Output is correct
38 Correct 96 ms 211792 KB Output is correct
39 Correct 82 ms 211800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 211792 KB Output is correct
2 Correct 76 ms 211668 KB Output is correct
3 Correct 94 ms 211560 KB Output is correct
4 Correct 80 ms 211732 KB Output is correct
5 Correct 97 ms 211808 KB Output is correct
6 Correct 84 ms 211720 KB Output is correct
7 Correct 92 ms 211796 KB Output is correct
8 Correct 107 ms 211616 KB Output is correct
9 Correct 86 ms 211592 KB Output is correct
10 Correct 105 ms 211792 KB Output is correct
11 Correct 84 ms 211700 KB Output is correct
12 Correct 87 ms 211852 KB Output is correct
13 Correct 75 ms 211796 KB Output is correct
14 Correct 86 ms 211680 KB Output is correct
15 Correct 81 ms 211796 KB Output is correct
16 Correct 84 ms 211796 KB Output is correct
17 Correct 82 ms 211756 KB Output is correct
18 Correct 76 ms 211660 KB Output is correct
19 Correct 108 ms 211796 KB Output is correct
20 Correct 74 ms 211796 KB Output is correct
21 Correct 82 ms 211796 KB Output is correct
22 Correct 98 ms 211860 KB Output is correct
23 Correct 73 ms 211772 KB Output is correct
24 Correct 81 ms 211944 KB Output is correct
25 Correct 78 ms 211796 KB Output is correct
26 Correct 99 ms 211792 KB Output is correct
27 Correct 104 ms 211904 KB Output is correct
28 Correct 76 ms 211792 KB Output is correct
29 Correct 93 ms 211792 KB Output is correct
30 Correct 74 ms 211792 KB Output is correct
31 Correct 104 ms 211792 KB Output is correct
32 Correct 73 ms 211796 KB Output is correct
33 Correct 100 ms 211876 KB Output is correct
34 Correct 78 ms 211692 KB Output is correct
35 Correct 76 ms 211792 KB Output is correct
36 Correct 77 ms 211800 KB Output is correct
37 Correct 80 ms 211792 KB Output is correct
38 Correct 96 ms 211792 KB Output is correct
39 Correct 82 ms 211800 KB Output is correct
40 Correct 90 ms 212304 KB Output is correct
41 Correct 164 ms 216036 KB Output is correct
42 Correct 196 ms 214076 KB Output is correct
43 Correct 262 ms 213840 KB Output is correct
44 Correct 187 ms 213664 KB Output is correct
45 Correct 210 ms 213644 KB Output is correct
46 Correct 211 ms 213388 KB Output is correct
47 Correct 227 ms 214140 KB Output is correct
48 Correct 163 ms 213696 KB Output is correct
49 Correct 186 ms 213680 KB Output is correct
50 Correct 172 ms 213836 KB Output is correct
51 Correct 169 ms 214612 KB Output is correct
52 Correct 188 ms 214428 KB Output is correct
53 Correct 172 ms 213588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 211792 KB Output is correct
2 Correct 76 ms 211668 KB Output is correct
3 Correct 94 ms 211560 KB Output is correct
4 Correct 80 ms 211732 KB Output is correct
5 Correct 97 ms 211808 KB Output is correct
6 Correct 84 ms 211720 KB Output is correct
7 Correct 92 ms 211796 KB Output is correct
8 Correct 107 ms 211616 KB Output is correct
9 Correct 86 ms 211592 KB Output is correct
10 Correct 105 ms 211792 KB Output is correct
11 Correct 84 ms 211700 KB Output is correct
12 Correct 87 ms 211852 KB Output is correct
13 Correct 75 ms 211796 KB Output is correct
14 Correct 86 ms 211680 KB Output is correct
15 Correct 81 ms 211796 KB Output is correct
16 Correct 84 ms 211796 KB Output is correct
17 Correct 82 ms 211756 KB Output is correct
18 Correct 76 ms 211660 KB Output is correct
19 Correct 108 ms 211796 KB Output is correct
20 Correct 74 ms 211796 KB Output is correct
21 Correct 82 ms 211796 KB Output is correct
22 Correct 98 ms 211860 KB Output is correct
23 Correct 73 ms 211772 KB Output is correct
24 Correct 81 ms 211944 KB Output is correct
25 Correct 78 ms 211796 KB Output is correct
26 Correct 99 ms 211792 KB Output is correct
27 Correct 104 ms 211904 KB Output is correct
28 Correct 76 ms 211792 KB Output is correct
29 Correct 93 ms 211792 KB Output is correct
30 Correct 74 ms 211792 KB Output is correct
31 Correct 104 ms 211792 KB Output is correct
32 Correct 73 ms 211796 KB Output is correct
33 Correct 100 ms 211876 KB Output is correct
34 Correct 78 ms 211692 KB Output is correct
35 Correct 76 ms 211792 KB Output is correct
36 Correct 77 ms 211800 KB Output is correct
37 Correct 80 ms 211792 KB Output is correct
38 Correct 96 ms 211792 KB Output is correct
39 Correct 82 ms 211800 KB Output is correct
40 Correct 90 ms 212304 KB Output is correct
41 Correct 164 ms 216036 KB Output is correct
42 Correct 196 ms 214076 KB Output is correct
43 Correct 262 ms 213840 KB Output is correct
44 Correct 187 ms 213664 KB Output is correct
45 Correct 210 ms 213644 KB Output is correct
46 Correct 211 ms 213388 KB Output is correct
47 Correct 227 ms 214140 KB Output is correct
48 Correct 163 ms 213696 KB Output is correct
49 Correct 186 ms 213680 KB Output is correct
50 Correct 172 ms 213836 KB Output is correct
51 Correct 169 ms 214612 KB Output is correct
52 Correct 188 ms 214428 KB Output is correct
53 Correct 172 ms 213588 KB Output is correct
54 Correct 2210 ms 221428 KB Output is correct
55 Execution timed out 3069 ms 324152 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 211792 KB Output is correct
2 Correct 76 ms 211668 KB Output is correct
3 Correct 94 ms 211560 KB Output is correct
4 Correct 80 ms 211732 KB Output is correct
5 Correct 97 ms 211808 KB Output is correct
6 Correct 84 ms 211720 KB Output is correct
7 Correct 92 ms 211796 KB Output is correct
8 Correct 107 ms 211616 KB Output is correct
9 Correct 86 ms 211592 KB Output is correct
10 Correct 105 ms 211792 KB Output is correct
11 Correct 83 ms 211860 KB Output is correct
12 Correct 101 ms 211796 KB Output is correct
13 Execution timed out 3105 ms 610028 KB Time limit exceeded
14 Halted 0 ms 0 KB -