Submission #549182

# Submission time Handle Problem Language Result Execution time Memory
549182 2022-04-15T11:28:01 Z nonsensenonsense1 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
448 ms 49580 KB
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>

const int md1 = 1000000787;
const int md2 = 1000000007;
const int g = 37;

inline int add(int a, int b, int md) {
	a += b;
	if (a >= md) a -= md;
	return a;
}
inline int sub(int a, int b, int md) {
	a -= b;
	if (a < 0) a += md;
	return a;
}
inline int mul(int a, int b, int md) {
	return (long long)a * b % md;
}

const int N = 2505;
int n, a, b, c, h1[N], h2[N], next[N];
long long d[N][N];
std::pair<long long, int> str[N];
char s[N];

inline void mnm(long long &a, long long b) {
	a = std::min(a, b);
}

int main() {
	scanf("%d%s%d%d%d", &n, s, &a, &b, &c);
	for (int i = 0; i < n; ++i) {
		h1[i + 1] = add(mul(h1[i], g, md1), s[i] - 'a', md1);
		h2[i + 1] = add(mul(h2[i], g, md2), s[i] - 'a', md2);
	}
	memset(*d, 0x3f, N * N << 3);
	for (int i = 0; i < n; ++i) d[i][i] = 0;
	int gg1 = 1, gg2 = 1;
	for (int l = 1; l <= n; ++l) {
		gg1 = mul(gg1, g, md1);
		gg2 = mul(gg2, g, md2);
		for (int i = 0; i + l <= n; ++i) {
			mnm(d[i][i + l], std::min(d[i][i + l - 1], d[i + 1][i + l]) + a);
			str[i] = std::make_pair((long long)sub(h1[i + l], mul(gg1, h1[i], md1), md1) << 32 | sub(h2[i + l], mul(gg2, h2[i], md2), md2), i);
		}
		std::sort(str, str + n - l + 1);
		for (int i = 0; i + l <= n;) {
			int fi = i, j = i;
			do {
				while (j + l <= n && str[j].first == str[i].first && str[i].second + l > str[j].second) ++j;
				next[i] = j;
				++i;
			} while (i + l <= n && str[i].first == str[i - 1].first);
			for (; fi < i; ++fi) {
				int cnt;
				for (j = fi, cnt = 1; j < i; j = next[j], ++cnt) mnm(d[str[fi].second][str[j].second + l], d[str[fi].second][str[fi].second + l] + b + (long long)cnt * c + (long long)a * (str[j].second + l - str[fi].second - cnt * l));
			}
		}
	}
	printf("%lld\n", d[0][n]);
	return 0;
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d%s%d%d%d", &n, s, &a, &b, &c);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49372 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 20 ms 49368 KB Output is correct
5 Correct 20 ms 49408 KB Output is correct
6 Correct 18 ms 49360 KB Output is correct
7 Correct 19 ms 49280 KB Output is correct
8 Correct 20 ms 49292 KB Output is correct
9 Correct 20 ms 49364 KB Output is correct
10 Correct 21 ms 49352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 49404 KB Output is correct
2 Correct 22 ms 49348 KB Output is correct
3 Correct 200 ms 49440 KB Output is correct
4 Correct 216 ms 49448 KB Output is correct
5 Correct 309 ms 49464 KB Output is correct
6 Correct 286 ms 49460 KB Output is correct
7 Correct 349 ms 49460 KB Output is correct
8 Correct 343 ms 49448 KB Output is correct
9 Correct 332 ms 49452 KB Output is correct
10 Correct 20 ms 49364 KB Output is correct
11 Correct 27 ms 49384 KB Output is correct
12 Correct 24 ms 49364 KB Output is correct
13 Correct 22 ms 49396 KB Output is correct
14 Correct 20 ms 49300 KB Output is correct
15 Correct 19 ms 49368 KB Output is correct
16 Correct 20 ms 49380 KB Output is correct
17 Correct 19 ms 49380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49372 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 20 ms 49368 KB Output is correct
5 Correct 20 ms 49408 KB Output is correct
6 Correct 18 ms 49360 KB Output is correct
7 Correct 19 ms 49280 KB Output is correct
8 Correct 20 ms 49292 KB Output is correct
9 Correct 20 ms 49364 KB Output is correct
10 Correct 21 ms 49352 KB Output is correct
11 Correct 19 ms 49364 KB Output is correct
12 Correct 19 ms 49308 KB Output is correct
13 Correct 19 ms 49428 KB Output is correct
14 Correct 19 ms 49380 KB Output is correct
15 Correct 20 ms 49364 KB Output is correct
16 Correct 19 ms 49364 KB Output is correct
17 Correct 20 ms 49372 KB Output is correct
18 Correct 25 ms 49372 KB Output is correct
19 Correct 25 ms 49364 KB Output is correct
20 Correct 21 ms 49388 KB Output is correct
21 Correct 21 ms 49340 KB Output is correct
22 Correct 23 ms 49404 KB Output is correct
23 Correct 20 ms 49408 KB Output is correct
24 Correct 19 ms 49364 KB Output is correct
25 Correct 19 ms 49324 KB Output is correct
26 Correct 19 ms 49364 KB Output is correct
27 Correct 19 ms 49328 KB Output is correct
28 Correct 20 ms 49316 KB Output is correct
29 Correct 21 ms 49404 KB Output is correct
30 Correct 20 ms 49364 KB Output is correct
31 Correct 20 ms 49364 KB Output is correct
32 Correct 22 ms 49364 KB Output is correct
33 Correct 21 ms 49384 KB Output is correct
34 Correct 21 ms 49416 KB Output is correct
35 Correct 23 ms 49312 KB Output is correct
36 Correct 19 ms 49404 KB Output is correct
37 Correct 19 ms 49328 KB Output is correct
38 Correct 21 ms 49392 KB Output is correct
39 Correct 20 ms 49364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49372 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 20 ms 49368 KB Output is correct
5 Correct 20 ms 49408 KB Output is correct
6 Correct 18 ms 49360 KB Output is correct
7 Correct 19 ms 49280 KB Output is correct
8 Correct 20 ms 49292 KB Output is correct
9 Correct 20 ms 49364 KB Output is correct
10 Correct 21 ms 49352 KB Output is correct
11 Correct 19 ms 49364 KB Output is correct
12 Correct 19 ms 49308 KB Output is correct
13 Correct 19 ms 49428 KB Output is correct
14 Correct 19 ms 49380 KB Output is correct
15 Correct 20 ms 49364 KB Output is correct
16 Correct 19 ms 49364 KB Output is correct
17 Correct 20 ms 49372 KB Output is correct
18 Correct 25 ms 49372 KB Output is correct
19 Correct 25 ms 49364 KB Output is correct
20 Correct 21 ms 49388 KB Output is correct
21 Correct 21 ms 49340 KB Output is correct
22 Correct 23 ms 49404 KB Output is correct
23 Correct 20 ms 49408 KB Output is correct
24 Correct 19 ms 49364 KB Output is correct
25 Correct 19 ms 49324 KB Output is correct
26 Correct 19 ms 49364 KB Output is correct
27 Correct 19 ms 49328 KB Output is correct
28 Correct 20 ms 49316 KB Output is correct
29 Correct 21 ms 49404 KB Output is correct
30 Correct 20 ms 49364 KB Output is correct
31 Correct 20 ms 49364 KB Output is correct
32 Correct 22 ms 49364 KB Output is correct
33 Correct 21 ms 49384 KB Output is correct
34 Correct 21 ms 49416 KB Output is correct
35 Correct 23 ms 49312 KB Output is correct
36 Correct 19 ms 49404 KB Output is correct
37 Correct 19 ms 49328 KB Output is correct
38 Correct 21 ms 49392 KB Output is correct
39 Correct 20 ms 49364 KB Output is correct
40 Correct 20 ms 49432 KB Output is correct
41 Correct 21 ms 49364 KB Output is correct
42 Correct 27 ms 49356 KB Output is correct
43 Correct 21 ms 49408 KB Output is correct
44 Correct 22 ms 49364 KB Output is correct
45 Correct 26 ms 49364 KB Output is correct
46 Correct 20 ms 49364 KB Output is correct
47 Correct 20 ms 49364 KB Output is correct
48 Correct 21 ms 49400 KB Output is correct
49 Correct 24 ms 49408 KB Output is correct
50 Correct 20 ms 49336 KB Output is correct
51 Correct 21 ms 49320 KB Output is correct
52 Correct 26 ms 49404 KB Output is correct
53 Correct 25 ms 49432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49372 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 20 ms 49368 KB Output is correct
5 Correct 20 ms 49408 KB Output is correct
6 Correct 18 ms 49360 KB Output is correct
7 Correct 19 ms 49280 KB Output is correct
8 Correct 20 ms 49292 KB Output is correct
9 Correct 20 ms 49364 KB Output is correct
10 Correct 21 ms 49352 KB Output is correct
11 Correct 19 ms 49364 KB Output is correct
12 Correct 19 ms 49308 KB Output is correct
13 Correct 19 ms 49428 KB Output is correct
14 Correct 19 ms 49380 KB Output is correct
15 Correct 20 ms 49364 KB Output is correct
16 Correct 19 ms 49364 KB Output is correct
17 Correct 20 ms 49372 KB Output is correct
18 Correct 25 ms 49372 KB Output is correct
19 Correct 25 ms 49364 KB Output is correct
20 Correct 21 ms 49388 KB Output is correct
21 Correct 21 ms 49340 KB Output is correct
22 Correct 23 ms 49404 KB Output is correct
23 Correct 20 ms 49408 KB Output is correct
24 Correct 19 ms 49364 KB Output is correct
25 Correct 19 ms 49324 KB Output is correct
26 Correct 19 ms 49364 KB Output is correct
27 Correct 19 ms 49328 KB Output is correct
28 Correct 20 ms 49316 KB Output is correct
29 Correct 21 ms 49404 KB Output is correct
30 Correct 20 ms 49364 KB Output is correct
31 Correct 20 ms 49364 KB Output is correct
32 Correct 22 ms 49364 KB Output is correct
33 Correct 21 ms 49384 KB Output is correct
34 Correct 21 ms 49416 KB Output is correct
35 Correct 23 ms 49312 KB Output is correct
36 Correct 19 ms 49404 KB Output is correct
37 Correct 19 ms 49328 KB Output is correct
38 Correct 21 ms 49392 KB Output is correct
39 Correct 20 ms 49364 KB Output is correct
40 Correct 20 ms 49432 KB Output is correct
41 Correct 21 ms 49364 KB Output is correct
42 Correct 27 ms 49356 KB Output is correct
43 Correct 21 ms 49408 KB Output is correct
44 Correct 22 ms 49364 KB Output is correct
45 Correct 26 ms 49364 KB Output is correct
46 Correct 20 ms 49364 KB Output is correct
47 Correct 20 ms 49364 KB Output is correct
48 Correct 21 ms 49400 KB Output is correct
49 Correct 24 ms 49408 KB Output is correct
50 Correct 20 ms 49336 KB Output is correct
51 Correct 21 ms 49320 KB Output is correct
52 Correct 26 ms 49404 KB Output is correct
53 Correct 25 ms 49432 KB Output is correct
54 Correct 27 ms 49352 KB Output is correct
55 Correct 52 ms 49428 KB Output is correct
56 Correct 54 ms 49364 KB Output is correct
57 Correct 59 ms 49428 KB Output is correct
58 Correct 54 ms 49428 KB Output is correct
59 Correct 55 ms 49432 KB Output is correct
60 Correct 56 ms 49364 KB Output is correct
61 Correct 63 ms 49368 KB Output is correct
62 Correct 59 ms 49428 KB Output is correct
63 Correct 58 ms 49432 KB Output is correct
64 Correct 61 ms 49428 KB Output is correct
65 Correct 88 ms 49432 KB Output is correct
66 Correct 70 ms 49424 KB Output is correct
67 Correct 52 ms 49432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49372 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 20 ms 49368 KB Output is correct
5 Correct 20 ms 49408 KB Output is correct
6 Correct 18 ms 49360 KB Output is correct
7 Correct 19 ms 49280 KB Output is correct
8 Correct 20 ms 49292 KB Output is correct
9 Correct 20 ms 49364 KB Output is correct
10 Correct 21 ms 49352 KB Output is correct
11 Correct 22 ms 49404 KB Output is correct
12 Correct 22 ms 49348 KB Output is correct
13 Correct 200 ms 49440 KB Output is correct
14 Correct 216 ms 49448 KB Output is correct
15 Correct 309 ms 49464 KB Output is correct
16 Correct 286 ms 49460 KB Output is correct
17 Correct 349 ms 49460 KB Output is correct
18 Correct 343 ms 49448 KB Output is correct
19 Correct 332 ms 49452 KB Output is correct
20 Correct 20 ms 49364 KB Output is correct
21 Correct 27 ms 49384 KB Output is correct
22 Correct 24 ms 49364 KB Output is correct
23 Correct 22 ms 49396 KB Output is correct
24 Correct 20 ms 49300 KB Output is correct
25 Correct 19 ms 49368 KB Output is correct
26 Correct 20 ms 49380 KB Output is correct
27 Correct 19 ms 49380 KB Output is correct
28 Correct 19 ms 49364 KB Output is correct
29 Correct 19 ms 49308 KB Output is correct
30 Correct 19 ms 49428 KB Output is correct
31 Correct 19 ms 49380 KB Output is correct
32 Correct 20 ms 49364 KB Output is correct
33 Correct 19 ms 49364 KB Output is correct
34 Correct 20 ms 49372 KB Output is correct
35 Correct 25 ms 49372 KB Output is correct
36 Correct 25 ms 49364 KB Output is correct
37 Correct 21 ms 49388 KB Output is correct
38 Correct 21 ms 49340 KB Output is correct
39 Correct 23 ms 49404 KB Output is correct
40 Correct 20 ms 49408 KB Output is correct
41 Correct 19 ms 49364 KB Output is correct
42 Correct 19 ms 49324 KB Output is correct
43 Correct 19 ms 49364 KB Output is correct
44 Correct 19 ms 49328 KB Output is correct
45 Correct 20 ms 49316 KB Output is correct
46 Correct 21 ms 49404 KB Output is correct
47 Correct 20 ms 49364 KB Output is correct
48 Correct 20 ms 49364 KB Output is correct
49 Correct 22 ms 49364 KB Output is correct
50 Correct 21 ms 49384 KB Output is correct
51 Correct 21 ms 49416 KB Output is correct
52 Correct 23 ms 49312 KB Output is correct
53 Correct 19 ms 49404 KB Output is correct
54 Correct 19 ms 49328 KB Output is correct
55 Correct 21 ms 49392 KB Output is correct
56 Correct 20 ms 49364 KB Output is correct
57 Correct 20 ms 49432 KB Output is correct
58 Correct 21 ms 49364 KB Output is correct
59 Correct 27 ms 49356 KB Output is correct
60 Correct 21 ms 49408 KB Output is correct
61 Correct 22 ms 49364 KB Output is correct
62 Correct 26 ms 49364 KB Output is correct
63 Correct 20 ms 49364 KB Output is correct
64 Correct 20 ms 49364 KB Output is correct
65 Correct 21 ms 49400 KB Output is correct
66 Correct 24 ms 49408 KB Output is correct
67 Correct 20 ms 49336 KB Output is correct
68 Correct 21 ms 49320 KB Output is correct
69 Correct 26 ms 49404 KB Output is correct
70 Correct 25 ms 49432 KB Output is correct
71 Correct 27 ms 49352 KB Output is correct
72 Correct 52 ms 49428 KB Output is correct
73 Correct 54 ms 49364 KB Output is correct
74 Correct 59 ms 49428 KB Output is correct
75 Correct 54 ms 49428 KB Output is correct
76 Correct 55 ms 49432 KB Output is correct
77 Correct 56 ms 49364 KB Output is correct
78 Correct 63 ms 49368 KB Output is correct
79 Correct 59 ms 49428 KB Output is correct
80 Correct 58 ms 49432 KB Output is correct
81 Correct 61 ms 49428 KB Output is correct
82 Correct 88 ms 49432 KB Output is correct
83 Correct 70 ms 49424 KB Output is correct
84 Correct 52 ms 49432 KB Output is correct
85 Correct 116 ms 49436 KB Output is correct
86 Correct 294 ms 49460 KB Output is correct
87 Correct 276 ms 49404 KB Output is correct
88 Correct 321 ms 49524 KB Output is correct
89 Correct 304 ms 49580 KB Output is correct
90 Correct 279 ms 49452 KB Output is correct
91 Correct 441 ms 49364 KB Output is correct
92 Correct 448 ms 49452 KB Output is correct
93 Correct 338 ms 49364 KB Output is correct
94 Correct 356 ms 49452 KB Output is correct
95 Correct 423 ms 49448 KB Output is correct
96 Correct 439 ms 49452 KB Output is correct
97 Correct 274 ms 49440 KB Output is correct