Submission #549177

# Submission time Handle Problem Language Result Execution time Memory
549177 2022-04-15T11:19:16 Z nonsensenonsense1 Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
330 ms 49504 KB
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>

const int md = 1000000007;
const int g = 44;

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

const int N = 2505;
int n, a, b, c, h[N], next[N];
long long d[N][N];
std::pair<int, 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) h[i + 1] = add(mul(h[i], g), s[i] - 'a');
	memset(*d, 0x3f, N * N << 3);
	for (int i = 0; i < n; ++i) d[i][i] = 0;
	int gg = 1;
	for (int l = 1; l <= n; ++l) {
		gg = mul(gg, g);
		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(sub(h[i + l], mul(gg, h[i])), 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:34:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d%s%d%d%d", &n, s, &a, &b, &c);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 49276 KB Output is correct
2 Correct 22 ms 49296 KB Output is correct
3 Correct 20 ms 49364 KB Output is correct
4 Correct 21 ms 49364 KB Output is correct
5 Correct 21 ms 49364 KB Output is correct
6 Correct 26 ms 49348 KB Output is correct
7 Correct 20 ms 49292 KB Output is correct
8 Correct 27 ms 49324 KB Output is correct
9 Correct 23 ms 49288 KB Output is correct
10 Correct 20 ms 49364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 49356 KB Output is correct
2 Correct 25 ms 49280 KB Output is correct
3 Correct 164 ms 49420 KB Output is correct
4 Correct 199 ms 49496 KB Output is correct
5 Correct 238 ms 49424 KB Output is correct
6 Correct 289 ms 49504 KB Output is correct
7 Correct 330 ms 49416 KB Output is correct
8 Correct 329 ms 49424 KB Output is correct
9 Correct 320 ms 49416 KB Output is correct
10 Correct 21 ms 49316 KB Output is correct
11 Correct 20 ms 49364 KB Output is correct
12 Correct 20 ms 49364 KB Output is correct
13 Correct 23 ms 49368 KB Output is correct
14 Correct 20 ms 49344 KB Output is correct
15 Correct 20 ms 49336 KB Output is correct
16 Correct 20 ms 49364 KB Output is correct
17 Correct 20 ms 49380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 49276 KB Output is correct
2 Correct 22 ms 49296 KB Output is correct
3 Correct 20 ms 49364 KB Output is correct
4 Correct 21 ms 49364 KB Output is correct
5 Correct 21 ms 49364 KB Output is correct
6 Correct 26 ms 49348 KB Output is correct
7 Correct 20 ms 49292 KB Output is correct
8 Correct 27 ms 49324 KB Output is correct
9 Correct 23 ms 49288 KB Output is correct
10 Correct 20 ms 49364 KB Output is correct
11 Correct 20 ms 49320 KB Output is correct
12 Correct 20 ms 49348 KB Output is correct
13 Correct 23 ms 49364 KB Output is correct
14 Correct 21 ms 49380 KB Output is correct
15 Correct 20 ms 49340 KB Output is correct
16 Correct 23 ms 49348 KB Output is correct
17 Correct 20 ms 49404 KB Output is correct
18 Correct 22 ms 49300 KB Output is correct
19 Correct 24 ms 49332 KB Output is correct
20 Correct 22 ms 49364 KB Output is correct
21 Correct 21 ms 49364 KB Output is correct
22 Correct 25 ms 49316 KB Output is correct
23 Correct 19 ms 49360 KB Output is correct
24 Correct 20 ms 49364 KB Output is correct
25 Correct 20 ms 49364 KB Output is correct
26 Correct 21 ms 49364 KB Output is correct
27 Correct 23 ms 49384 KB Output is correct
28 Correct 21 ms 49364 KB Output is correct
29 Correct 21 ms 49412 KB Output is correct
30 Correct 21 ms 49364 KB Output is correct
31 Correct 20 ms 49364 KB Output is correct
32 Correct 20 ms 49320 KB Output is correct
33 Correct 21 ms 49364 KB Output is correct
34 Correct 20 ms 49328 KB Output is correct
35 Correct 20 ms 49364 KB Output is correct
36 Correct 20 ms 49344 KB Output is correct
37 Correct 20 ms 49376 KB Output is correct
38 Correct 21 ms 49348 KB Output is correct
39 Correct 22 ms 49376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 49276 KB Output is correct
2 Correct 22 ms 49296 KB Output is correct
3 Correct 20 ms 49364 KB Output is correct
4 Correct 21 ms 49364 KB Output is correct
5 Correct 21 ms 49364 KB Output is correct
6 Correct 26 ms 49348 KB Output is correct
7 Correct 20 ms 49292 KB Output is correct
8 Correct 27 ms 49324 KB Output is correct
9 Correct 23 ms 49288 KB Output is correct
10 Correct 20 ms 49364 KB Output is correct
11 Correct 20 ms 49320 KB Output is correct
12 Correct 20 ms 49348 KB Output is correct
13 Correct 23 ms 49364 KB Output is correct
14 Correct 21 ms 49380 KB Output is correct
15 Correct 20 ms 49340 KB Output is correct
16 Correct 23 ms 49348 KB Output is correct
17 Correct 20 ms 49404 KB Output is correct
18 Correct 22 ms 49300 KB Output is correct
19 Correct 24 ms 49332 KB Output is correct
20 Correct 22 ms 49364 KB Output is correct
21 Correct 21 ms 49364 KB Output is correct
22 Correct 25 ms 49316 KB Output is correct
23 Correct 19 ms 49360 KB Output is correct
24 Correct 20 ms 49364 KB Output is correct
25 Correct 20 ms 49364 KB Output is correct
26 Correct 21 ms 49364 KB Output is correct
27 Correct 23 ms 49384 KB Output is correct
28 Correct 21 ms 49364 KB Output is correct
29 Correct 21 ms 49412 KB Output is correct
30 Correct 21 ms 49364 KB Output is correct
31 Correct 20 ms 49364 KB Output is correct
32 Correct 20 ms 49320 KB Output is correct
33 Correct 21 ms 49364 KB Output is correct
34 Correct 20 ms 49328 KB Output is correct
35 Correct 20 ms 49364 KB Output is correct
36 Correct 20 ms 49344 KB Output is correct
37 Correct 20 ms 49376 KB Output is correct
38 Correct 21 ms 49348 KB Output is correct
39 Correct 22 ms 49376 KB Output is correct
40 Correct 21 ms 49388 KB Output is correct
41 Correct 21 ms 49364 KB Output is correct
42 Correct 20 ms 49348 KB Output is correct
43 Correct 20 ms 49280 KB Output is correct
44 Correct 20 ms 49320 KB Output is correct
45 Correct 20 ms 49400 KB Output is correct
46 Correct 22 ms 49396 KB Output is correct
47 Correct 26 ms 49328 KB Output is correct
48 Correct 22 ms 49412 KB Output is correct
49 Correct 22 ms 49416 KB Output is correct
50 Correct 21 ms 49312 KB Output is correct
51 Correct 21 ms 49320 KB Output is correct
52 Correct 22 ms 49312 KB Output is correct
53 Correct 21 ms 49492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 49276 KB Output is correct
2 Correct 22 ms 49296 KB Output is correct
3 Correct 20 ms 49364 KB Output is correct
4 Correct 21 ms 49364 KB Output is correct
5 Correct 21 ms 49364 KB Output is correct
6 Correct 26 ms 49348 KB Output is correct
7 Correct 20 ms 49292 KB Output is correct
8 Correct 27 ms 49324 KB Output is correct
9 Correct 23 ms 49288 KB Output is correct
10 Correct 20 ms 49364 KB Output is correct
11 Correct 20 ms 49320 KB Output is correct
12 Correct 20 ms 49348 KB Output is correct
13 Correct 23 ms 49364 KB Output is correct
14 Correct 21 ms 49380 KB Output is correct
15 Correct 20 ms 49340 KB Output is correct
16 Correct 23 ms 49348 KB Output is correct
17 Correct 20 ms 49404 KB Output is correct
18 Correct 22 ms 49300 KB Output is correct
19 Correct 24 ms 49332 KB Output is correct
20 Correct 22 ms 49364 KB Output is correct
21 Correct 21 ms 49364 KB Output is correct
22 Correct 25 ms 49316 KB Output is correct
23 Correct 19 ms 49360 KB Output is correct
24 Correct 20 ms 49364 KB Output is correct
25 Correct 20 ms 49364 KB Output is correct
26 Correct 21 ms 49364 KB Output is correct
27 Correct 23 ms 49384 KB Output is correct
28 Correct 21 ms 49364 KB Output is correct
29 Correct 21 ms 49412 KB Output is correct
30 Correct 21 ms 49364 KB Output is correct
31 Correct 20 ms 49364 KB Output is correct
32 Correct 20 ms 49320 KB Output is correct
33 Correct 21 ms 49364 KB Output is correct
34 Correct 20 ms 49328 KB Output is correct
35 Correct 20 ms 49364 KB Output is correct
36 Correct 20 ms 49344 KB Output is correct
37 Correct 20 ms 49376 KB Output is correct
38 Correct 21 ms 49348 KB Output is correct
39 Correct 22 ms 49376 KB Output is correct
40 Correct 21 ms 49388 KB Output is correct
41 Correct 21 ms 49364 KB Output is correct
42 Correct 20 ms 49348 KB Output is correct
43 Correct 20 ms 49280 KB Output is correct
44 Correct 20 ms 49320 KB Output is correct
45 Correct 20 ms 49400 KB Output is correct
46 Correct 22 ms 49396 KB Output is correct
47 Correct 26 ms 49328 KB Output is correct
48 Correct 22 ms 49412 KB Output is correct
49 Correct 22 ms 49416 KB Output is correct
50 Correct 21 ms 49312 KB Output is correct
51 Correct 21 ms 49320 KB Output is correct
52 Correct 22 ms 49312 KB Output is correct
53 Correct 21 ms 49492 KB Output is correct
54 Correct 27 ms 49420 KB Output is correct
55 Correct 48 ms 49364 KB Output is correct
56 Correct 51 ms 49316 KB Output is correct
57 Correct 51 ms 49324 KB Output is correct
58 Correct 50 ms 49356 KB Output is correct
59 Correct 53 ms 49380 KB Output is correct
60 Correct 52 ms 49408 KB Output is correct
61 Correct 62 ms 49404 KB Output is correct
62 Correct 61 ms 49476 KB Output is correct
63 Correct 58 ms 49408 KB Output is correct
64 Correct 57 ms 49364 KB Output is correct
65 Correct 67 ms 49420 KB Output is correct
66 Correct 68 ms 49412 KB Output is correct
67 Correct 51 ms 49412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 49276 KB Output is correct
2 Correct 22 ms 49296 KB Output is correct
3 Correct 20 ms 49364 KB Output is correct
4 Correct 21 ms 49364 KB Output is correct
5 Correct 21 ms 49364 KB Output is correct
6 Correct 26 ms 49348 KB Output is correct
7 Correct 20 ms 49292 KB Output is correct
8 Correct 27 ms 49324 KB Output is correct
9 Correct 23 ms 49288 KB Output is correct
10 Correct 20 ms 49364 KB Output is correct
11 Correct 22 ms 49356 KB Output is correct
12 Correct 25 ms 49280 KB Output is correct
13 Correct 164 ms 49420 KB Output is correct
14 Correct 199 ms 49496 KB Output is correct
15 Correct 238 ms 49424 KB Output is correct
16 Correct 289 ms 49504 KB Output is correct
17 Correct 330 ms 49416 KB Output is correct
18 Correct 329 ms 49424 KB Output is correct
19 Correct 320 ms 49416 KB Output is correct
20 Correct 21 ms 49316 KB Output is correct
21 Correct 20 ms 49364 KB Output is correct
22 Correct 20 ms 49364 KB Output is correct
23 Correct 23 ms 49368 KB Output is correct
24 Correct 20 ms 49344 KB Output is correct
25 Correct 20 ms 49336 KB Output is correct
26 Correct 20 ms 49364 KB Output is correct
27 Correct 20 ms 49380 KB Output is correct
28 Correct 20 ms 49320 KB Output is correct
29 Correct 20 ms 49348 KB Output is correct
30 Correct 23 ms 49364 KB Output is correct
31 Correct 21 ms 49380 KB Output is correct
32 Correct 20 ms 49340 KB Output is correct
33 Correct 23 ms 49348 KB Output is correct
34 Correct 20 ms 49404 KB Output is correct
35 Correct 22 ms 49300 KB Output is correct
36 Correct 24 ms 49332 KB Output is correct
37 Correct 22 ms 49364 KB Output is correct
38 Correct 21 ms 49364 KB Output is correct
39 Correct 25 ms 49316 KB Output is correct
40 Correct 19 ms 49360 KB Output is correct
41 Correct 20 ms 49364 KB Output is correct
42 Correct 20 ms 49364 KB Output is correct
43 Correct 21 ms 49364 KB Output is correct
44 Correct 23 ms 49384 KB Output is correct
45 Correct 21 ms 49364 KB Output is correct
46 Correct 21 ms 49412 KB Output is correct
47 Correct 21 ms 49364 KB Output is correct
48 Correct 20 ms 49364 KB Output is correct
49 Correct 20 ms 49320 KB Output is correct
50 Correct 21 ms 49364 KB Output is correct
51 Correct 20 ms 49328 KB Output is correct
52 Correct 20 ms 49364 KB Output is correct
53 Correct 20 ms 49344 KB Output is correct
54 Correct 20 ms 49376 KB Output is correct
55 Correct 21 ms 49348 KB Output is correct
56 Correct 22 ms 49376 KB Output is correct
57 Correct 21 ms 49388 KB Output is correct
58 Correct 21 ms 49364 KB Output is correct
59 Correct 20 ms 49348 KB Output is correct
60 Correct 20 ms 49280 KB Output is correct
61 Correct 20 ms 49320 KB Output is correct
62 Correct 20 ms 49400 KB Output is correct
63 Correct 22 ms 49396 KB Output is correct
64 Correct 26 ms 49328 KB Output is correct
65 Correct 22 ms 49412 KB Output is correct
66 Correct 22 ms 49416 KB Output is correct
67 Correct 21 ms 49312 KB Output is correct
68 Correct 21 ms 49320 KB Output is correct
69 Correct 22 ms 49312 KB Output is correct
70 Correct 21 ms 49492 KB Output is correct
71 Correct 27 ms 49420 KB Output is correct
72 Correct 48 ms 49364 KB Output is correct
73 Correct 51 ms 49316 KB Output is correct
74 Correct 51 ms 49324 KB Output is correct
75 Correct 50 ms 49356 KB Output is correct
76 Correct 53 ms 49380 KB Output is correct
77 Correct 52 ms 49408 KB Output is correct
78 Correct 62 ms 49404 KB Output is correct
79 Correct 61 ms 49476 KB Output is correct
80 Correct 58 ms 49408 KB Output is correct
81 Correct 57 ms 49364 KB Output is correct
82 Correct 67 ms 49420 KB Output is correct
83 Correct 68 ms 49412 KB Output is correct
84 Correct 51 ms 49412 KB Output is correct
85 Correct 110 ms 49412 KB Output is correct
86 Correct 255 ms 49416 KB Output is correct
87 Correct 241 ms 49364 KB Output is correct
88 Correct 241 ms 49424 KB Output is correct
89 Incorrect 240 ms 49420 KB Output isn't correct
90 Halted 0 ms 0 KB -