Submission #558014

# Submission time Handle Problem Language Result Execution time Memory
558014 2022-05-06T13:35:26 Z DanShaders Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
828 ms 54208 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;

template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;

#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;

const int N = 2510;
const ll INF = 0x3f3f3f3f3f3f3f3f;

ll dp[N][N];
int nxt[N][N];

int pref[N];

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	int n;
	ll a, b, c;
	string s;
	cin >> n >> s >> a >> b >> c;
	for (int i = 0; i < n; ++i) {
		fill(pref, pref + n, 0);
		pref[i] = n - i;
		int zbegin = 0, zend = 0;
		for (int j = i + 1; j < n; ++j) {
			if (zend > j) {
				pref[j] = min(zend - j, pref[i + j - zbegin]);
			}
			while (s[j + pref[j]] == s[i + pref[j]]) {
				++pref[j];
			}
			if (zend < j + pref[j]) {
				zbegin = j;
				zend = j + pref[j];
			}
		}

		int mx = 1;
		for (int j = i + 1; j <= n; ++j) {
			nxt[i][j] = n;
			for (; mx <= min(j - i, pref[j]); ++mx) {
				nxt[i][i + mx] = j;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			dp[i][j] = (j - i) * a;
		}
	}
	for (int len = 1; len <= n; ++len) {
		for (int i = 0; i <= n - len; ++i) {
			int at = nxt[i][i + len];
			ll curr = dp[i][i + len] + b + 2 * c + (at - i - len) * a;
			while (at != n) {
				dp[i][at + len] = min(curr, dp[i][at + len]);
				int prv = at;
				at = nxt[at][at + len];
				curr += c + (at - prv - len) * a;
			}
		}
		if (!(len & (len - 1))) {
			for (int len2 = len; len2 <= n; ++len2) {
				for (int i = 0; i <= n - len2; ++i) {
					dp[i][i + len2] = min({dp[i][i + len2], dp[i][i + len2 - 1] + a, dp[i + 1][i + len2] + a});
				}
			}
		}
	}
	for (int len2 = 1; len2 <= n; ++len2) {
		for (int i = 0; i <= n - len2; ++i) {
			dp[i][i + len2] = min({dp[i][i + len2], dp[i][i + len2 - 1] + a, dp[i + 1][i + len2] + a});
		}
	}
	cout << dp[0][n];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 285 ms 34388 KB Output is correct
4 Correct 400 ms 38656 KB Output is correct
5 Correct 487 ms 43448 KB Output is correct
6 Correct 663 ms 48524 KB Output is correct
7 Correct 797 ms 54096 KB Output is correct
8 Correct 797 ms 54092 KB Output is correct
9 Correct 828 ms 54088 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 548 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 0 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 548 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 0 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 2 ms 2132 KB Output is correct
42 Correct 2 ms 2132 KB Output is correct
43 Correct 2 ms 2132 KB Output is correct
44 Correct 1 ms 2132 KB Output is correct
45 Correct 1 ms 2132 KB Output is correct
46 Correct 2 ms 2132 KB Output is correct
47 Correct 2 ms 2132 KB Output is correct
48 Correct 2 ms 2132 KB Output is correct
49 Correct 2 ms 2132 KB Output is correct
50 Correct 2 ms 2132 KB Output is correct
51 Correct 2 ms 2132 KB Output is correct
52 Correct 2 ms 2132 KB Output is correct
53 Correct 1 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 548 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 0 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 2 ms 2132 KB Output is correct
42 Correct 2 ms 2132 KB Output is correct
43 Correct 2 ms 2132 KB Output is correct
44 Correct 1 ms 2132 KB Output is correct
45 Correct 1 ms 2132 KB Output is correct
46 Correct 2 ms 2132 KB Output is correct
47 Correct 2 ms 2132 KB Output is correct
48 Correct 2 ms 2132 KB Output is correct
49 Correct 2 ms 2132 KB Output is correct
50 Correct 2 ms 2132 KB Output is correct
51 Correct 2 ms 2132 KB Output is correct
52 Correct 2 ms 2132 KB Output is correct
53 Correct 1 ms 2132 KB Output is correct
54 Correct 6 ms 5076 KB Output is correct
55 Correct 56 ms 14232 KB Output is correct
56 Correct 29 ms 14164 KB Output is correct
57 Correct 27 ms 14132 KB Output is correct
58 Correct 25 ms 14256 KB Output is correct
59 Correct 23 ms 14256 KB Output is correct
60 Correct 26 ms 14164 KB Output is correct
61 Correct 28 ms 14256 KB Output is correct
62 Correct 60 ms 14240 KB Output is correct
63 Correct 28 ms 14244 KB Output is correct
64 Correct 26 ms 14256 KB Output is correct
65 Correct 35 ms 14164 KB Output is correct
66 Correct 35 ms 14164 KB Output is correct
67 Correct 21 ms 14164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 285 ms 34388 KB Output is correct
14 Correct 400 ms 38656 KB Output is correct
15 Correct 487 ms 43448 KB Output is correct
16 Correct 663 ms 48524 KB Output is correct
17 Correct 797 ms 54096 KB Output is correct
18 Correct 797 ms 54092 KB Output is correct
19 Correct 828 ms 54088 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 548 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
41 Correct 0 ms 468 KB Output is correct
42 Correct 0 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 0 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 0 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 0 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 0 ms 340 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 980 KB Output is correct
58 Correct 2 ms 2132 KB Output is correct
59 Correct 2 ms 2132 KB Output is correct
60 Correct 2 ms 2132 KB Output is correct
61 Correct 1 ms 2132 KB Output is correct
62 Correct 1 ms 2132 KB Output is correct
63 Correct 2 ms 2132 KB Output is correct
64 Correct 2 ms 2132 KB Output is correct
65 Correct 2 ms 2132 KB Output is correct
66 Correct 2 ms 2132 KB Output is correct
67 Correct 2 ms 2132 KB Output is correct
68 Correct 2 ms 2132 KB Output is correct
69 Correct 2 ms 2132 KB Output is correct
70 Correct 1 ms 2132 KB Output is correct
71 Correct 6 ms 5076 KB Output is correct
72 Correct 56 ms 14232 KB Output is correct
73 Correct 29 ms 14164 KB Output is correct
74 Correct 27 ms 14132 KB Output is correct
75 Correct 25 ms 14256 KB Output is correct
76 Correct 23 ms 14256 KB Output is correct
77 Correct 26 ms 14164 KB Output is correct
78 Correct 28 ms 14256 KB Output is correct
79 Correct 60 ms 14240 KB Output is correct
80 Correct 28 ms 14244 KB Output is correct
81 Correct 26 ms 14256 KB Output is correct
82 Correct 35 ms 14164 KB Output is correct
83 Correct 35 ms 14164 KB Output is correct
84 Correct 21 ms 14164 KB Output is correct
85 Correct 106 ms 27668 KB Output is correct
86 Correct 347 ms 54208 KB Output is correct
87 Correct 327 ms 54004 KB Output is correct
88 Correct 304 ms 54088 KB Output is correct
89 Correct 301 ms 54092 KB Output is correct
90 Correct 293 ms 54092 KB Output is correct
91 Correct 479 ms 54088 KB Output is correct
92 Correct 604 ms 54124 KB Output is correct
93 Correct 314 ms 54092 KB Output is correct
94 Correct 362 ms 54092 KB Output is correct
95 Correct 504 ms 54052 KB Output is correct
96 Correct 477 ms 54092 KB Output is correct
97 Correct 292 ms 54012 KB Output is correct