답안 #549180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549180 2022-04-15T11:25:16 Z nonsensenonsense1 Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
389 ms 49492 KB
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>

const int md = 1000000787;
const int g = 37;

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);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49376 KB Output is correct
3 Correct 19 ms 49348 KB Output is correct
4 Correct 20 ms 49380 KB Output is correct
5 Correct 20 ms 49348 KB Output is correct
6 Correct 19 ms 49312 KB Output is correct
7 Correct 22 ms 49492 KB Output is correct
8 Correct 22 ms 49392 KB Output is correct
9 Correct 23 ms 49340 KB Output is correct
10 Correct 25 ms 49356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 49376 KB Output is correct
2 Correct 22 ms 49368 KB Output is correct
3 Correct 193 ms 49416 KB Output is correct
4 Correct 212 ms 49424 KB Output is correct
5 Correct 269 ms 49416 KB Output is correct
6 Correct 318 ms 49424 KB Output is correct
7 Correct 381 ms 49424 KB Output is correct
8 Correct 389 ms 49420 KB Output is correct
9 Correct 362 ms 49428 KB Output is correct
10 Correct 21 ms 49292 KB Output is correct
11 Correct 25 ms 49364 KB Output is correct
12 Correct 20 ms 49416 KB Output is correct
13 Correct 23 ms 49396 KB Output is correct
14 Correct 25 ms 49316 KB Output is correct
15 Correct 21 ms 49380 KB Output is correct
16 Correct 28 ms 49364 KB Output is correct
17 Correct 26 ms 49376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49376 KB Output is correct
3 Correct 19 ms 49348 KB Output is correct
4 Correct 20 ms 49380 KB Output is correct
5 Correct 20 ms 49348 KB Output is correct
6 Correct 19 ms 49312 KB Output is correct
7 Correct 22 ms 49492 KB Output is correct
8 Correct 22 ms 49392 KB Output is correct
9 Correct 23 ms 49340 KB Output is correct
10 Correct 25 ms 49356 KB Output is correct
11 Correct 22 ms 49364 KB Output is correct
12 Correct 22 ms 49364 KB Output is correct
13 Correct 22 ms 49364 KB Output is correct
14 Correct 28 ms 49284 KB Output is correct
15 Correct 25 ms 49352 KB Output is correct
16 Correct 21 ms 49368 KB Output is correct
17 Correct 21 ms 49356 KB Output is correct
18 Correct 20 ms 49364 KB Output is correct
19 Correct 19 ms 49364 KB Output is correct
20 Correct 19 ms 49392 KB Output is correct
21 Correct 23 ms 49360 KB Output is correct
22 Correct 25 ms 49328 KB Output is correct
23 Correct 22 ms 49348 KB Output is correct
24 Correct 20 ms 49408 KB Output is correct
25 Correct 21 ms 49364 KB Output is correct
26 Correct 20 ms 49344 KB Output is correct
27 Correct 19 ms 49364 KB Output is correct
28 Correct 20 ms 49308 KB Output is correct
29 Correct 20 ms 49364 KB Output is correct
30 Correct 19 ms 49332 KB Output is correct
31 Correct 21 ms 49408 KB Output is correct
32 Correct 21 ms 49388 KB Output is correct
33 Correct 21 ms 49304 KB Output is correct
34 Correct 24 ms 49304 KB Output is correct
35 Correct 19 ms 49336 KB Output is correct
36 Correct 20 ms 49408 KB Output is correct
37 Correct 20 ms 49360 KB Output is correct
38 Correct 21 ms 49392 KB Output is correct
39 Correct 20 ms 49368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49376 KB Output is correct
3 Correct 19 ms 49348 KB Output is correct
4 Correct 20 ms 49380 KB Output is correct
5 Correct 20 ms 49348 KB Output is correct
6 Correct 19 ms 49312 KB Output is correct
7 Correct 22 ms 49492 KB Output is correct
8 Correct 22 ms 49392 KB Output is correct
9 Correct 23 ms 49340 KB Output is correct
10 Correct 25 ms 49356 KB Output is correct
11 Correct 22 ms 49364 KB Output is correct
12 Correct 22 ms 49364 KB Output is correct
13 Correct 22 ms 49364 KB Output is correct
14 Correct 28 ms 49284 KB Output is correct
15 Correct 25 ms 49352 KB Output is correct
16 Correct 21 ms 49368 KB Output is correct
17 Correct 21 ms 49356 KB Output is correct
18 Correct 20 ms 49364 KB Output is correct
19 Correct 19 ms 49364 KB Output is correct
20 Correct 19 ms 49392 KB Output is correct
21 Correct 23 ms 49360 KB Output is correct
22 Correct 25 ms 49328 KB Output is correct
23 Correct 22 ms 49348 KB Output is correct
24 Correct 20 ms 49408 KB Output is correct
25 Correct 21 ms 49364 KB Output is correct
26 Correct 20 ms 49344 KB Output is correct
27 Correct 19 ms 49364 KB Output is correct
28 Correct 20 ms 49308 KB Output is correct
29 Correct 20 ms 49364 KB Output is correct
30 Correct 19 ms 49332 KB Output is correct
31 Correct 21 ms 49408 KB Output is correct
32 Correct 21 ms 49388 KB Output is correct
33 Correct 21 ms 49304 KB Output is correct
34 Correct 24 ms 49304 KB Output is correct
35 Correct 19 ms 49336 KB Output is correct
36 Correct 20 ms 49408 KB Output is correct
37 Correct 20 ms 49360 KB Output is correct
38 Correct 21 ms 49392 KB Output is correct
39 Correct 20 ms 49368 KB Output is correct
40 Correct 20 ms 49352 KB Output is correct
41 Correct 20 ms 49344 KB Output is correct
42 Correct 21 ms 49324 KB Output is correct
43 Correct 25 ms 49304 KB Output is correct
44 Correct 25 ms 49332 KB Output is correct
45 Correct 22 ms 49364 KB Output is correct
46 Correct 23 ms 49412 KB Output is correct
47 Correct 22 ms 49364 KB Output is correct
48 Correct 22 ms 49392 KB Output is correct
49 Correct 22 ms 49364 KB Output is correct
50 Correct 21 ms 49408 KB Output is correct
51 Correct 22 ms 49300 KB Output is correct
52 Correct 30 ms 49364 KB Output is correct
53 Correct 24 ms 49396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49376 KB Output is correct
3 Correct 19 ms 49348 KB Output is correct
4 Correct 20 ms 49380 KB Output is correct
5 Correct 20 ms 49348 KB Output is correct
6 Correct 19 ms 49312 KB Output is correct
7 Correct 22 ms 49492 KB Output is correct
8 Correct 22 ms 49392 KB Output is correct
9 Correct 23 ms 49340 KB Output is correct
10 Correct 25 ms 49356 KB Output is correct
11 Correct 22 ms 49364 KB Output is correct
12 Correct 22 ms 49364 KB Output is correct
13 Correct 22 ms 49364 KB Output is correct
14 Correct 28 ms 49284 KB Output is correct
15 Correct 25 ms 49352 KB Output is correct
16 Correct 21 ms 49368 KB Output is correct
17 Correct 21 ms 49356 KB Output is correct
18 Correct 20 ms 49364 KB Output is correct
19 Correct 19 ms 49364 KB Output is correct
20 Correct 19 ms 49392 KB Output is correct
21 Correct 23 ms 49360 KB Output is correct
22 Correct 25 ms 49328 KB Output is correct
23 Correct 22 ms 49348 KB Output is correct
24 Correct 20 ms 49408 KB Output is correct
25 Correct 21 ms 49364 KB Output is correct
26 Correct 20 ms 49344 KB Output is correct
27 Correct 19 ms 49364 KB Output is correct
28 Correct 20 ms 49308 KB Output is correct
29 Correct 20 ms 49364 KB Output is correct
30 Correct 19 ms 49332 KB Output is correct
31 Correct 21 ms 49408 KB Output is correct
32 Correct 21 ms 49388 KB Output is correct
33 Correct 21 ms 49304 KB Output is correct
34 Correct 24 ms 49304 KB Output is correct
35 Correct 19 ms 49336 KB Output is correct
36 Correct 20 ms 49408 KB Output is correct
37 Correct 20 ms 49360 KB Output is correct
38 Correct 21 ms 49392 KB Output is correct
39 Correct 20 ms 49368 KB Output is correct
40 Correct 20 ms 49352 KB Output is correct
41 Correct 20 ms 49344 KB Output is correct
42 Correct 21 ms 49324 KB Output is correct
43 Correct 25 ms 49304 KB Output is correct
44 Correct 25 ms 49332 KB Output is correct
45 Correct 22 ms 49364 KB Output is correct
46 Correct 23 ms 49412 KB Output is correct
47 Correct 22 ms 49364 KB Output is correct
48 Correct 22 ms 49392 KB Output is correct
49 Correct 22 ms 49364 KB Output is correct
50 Correct 21 ms 49408 KB Output is correct
51 Correct 22 ms 49300 KB Output is correct
52 Correct 30 ms 49364 KB Output is correct
53 Correct 24 ms 49396 KB Output is correct
54 Correct 32 ms 49384 KB Output is correct
55 Correct 69 ms 49404 KB Output is correct
56 Correct 61 ms 49364 KB Output is correct
57 Correct 61 ms 49408 KB Output is correct
58 Correct 60 ms 49408 KB Output is correct
59 Correct 60 ms 49424 KB Output is correct
60 Correct 59 ms 49324 KB Output is correct
61 Correct 65 ms 49416 KB Output is correct
62 Correct 78 ms 49376 KB Output is correct
63 Correct 60 ms 49408 KB Output is correct
64 Correct 74 ms 49404 KB Output is correct
65 Correct 78 ms 49356 KB Output is correct
66 Correct 82 ms 49412 KB Output is correct
67 Correct 57 ms 49408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49376 KB Output is correct
3 Correct 19 ms 49348 KB Output is correct
4 Correct 20 ms 49380 KB Output is correct
5 Correct 20 ms 49348 KB Output is correct
6 Correct 19 ms 49312 KB Output is correct
7 Correct 22 ms 49492 KB Output is correct
8 Correct 22 ms 49392 KB Output is correct
9 Correct 23 ms 49340 KB Output is correct
10 Correct 25 ms 49356 KB Output is correct
11 Correct 23 ms 49376 KB Output is correct
12 Correct 22 ms 49368 KB Output is correct
13 Correct 193 ms 49416 KB Output is correct
14 Correct 212 ms 49424 KB Output is correct
15 Correct 269 ms 49416 KB Output is correct
16 Correct 318 ms 49424 KB Output is correct
17 Correct 381 ms 49424 KB Output is correct
18 Correct 389 ms 49420 KB Output is correct
19 Correct 362 ms 49428 KB Output is correct
20 Correct 21 ms 49292 KB Output is correct
21 Correct 25 ms 49364 KB Output is correct
22 Correct 20 ms 49416 KB Output is correct
23 Correct 23 ms 49396 KB Output is correct
24 Correct 25 ms 49316 KB Output is correct
25 Correct 21 ms 49380 KB Output is correct
26 Correct 28 ms 49364 KB Output is correct
27 Correct 26 ms 49376 KB Output is correct
28 Correct 22 ms 49364 KB Output is correct
29 Correct 22 ms 49364 KB Output is correct
30 Correct 22 ms 49364 KB Output is correct
31 Correct 28 ms 49284 KB Output is correct
32 Correct 25 ms 49352 KB Output is correct
33 Correct 21 ms 49368 KB Output is correct
34 Correct 21 ms 49356 KB Output is correct
35 Correct 20 ms 49364 KB Output is correct
36 Correct 19 ms 49364 KB Output is correct
37 Correct 19 ms 49392 KB Output is correct
38 Correct 23 ms 49360 KB Output is correct
39 Correct 25 ms 49328 KB Output is correct
40 Correct 22 ms 49348 KB Output is correct
41 Correct 20 ms 49408 KB Output is correct
42 Correct 21 ms 49364 KB Output is correct
43 Correct 20 ms 49344 KB Output is correct
44 Correct 19 ms 49364 KB Output is correct
45 Correct 20 ms 49308 KB Output is correct
46 Correct 20 ms 49364 KB Output is correct
47 Correct 19 ms 49332 KB Output is correct
48 Correct 21 ms 49408 KB Output is correct
49 Correct 21 ms 49388 KB Output is correct
50 Correct 21 ms 49304 KB Output is correct
51 Correct 24 ms 49304 KB Output is correct
52 Correct 19 ms 49336 KB Output is correct
53 Correct 20 ms 49408 KB Output is correct
54 Correct 20 ms 49360 KB Output is correct
55 Correct 21 ms 49392 KB Output is correct
56 Correct 20 ms 49368 KB Output is correct
57 Correct 20 ms 49352 KB Output is correct
58 Correct 20 ms 49344 KB Output is correct
59 Correct 21 ms 49324 KB Output is correct
60 Correct 25 ms 49304 KB Output is correct
61 Correct 25 ms 49332 KB Output is correct
62 Correct 22 ms 49364 KB Output is correct
63 Correct 23 ms 49412 KB Output is correct
64 Correct 22 ms 49364 KB Output is correct
65 Correct 22 ms 49392 KB Output is correct
66 Correct 22 ms 49364 KB Output is correct
67 Correct 21 ms 49408 KB Output is correct
68 Correct 22 ms 49300 KB Output is correct
69 Correct 30 ms 49364 KB Output is correct
70 Correct 24 ms 49396 KB Output is correct
71 Correct 32 ms 49384 KB Output is correct
72 Correct 69 ms 49404 KB Output is correct
73 Correct 61 ms 49364 KB Output is correct
74 Correct 61 ms 49408 KB Output is correct
75 Correct 60 ms 49408 KB Output is correct
76 Correct 60 ms 49424 KB Output is correct
77 Correct 59 ms 49324 KB Output is correct
78 Correct 65 ms 49416 KB Output is correct
79 Correct 78 ms 49376 KB Output is correct
80 Correct 60 ms 49408 KB Output is correct
81 Correct 74 ms 49404 KB Output is correct
82 Correct 78 ms 49356 KB Output is correct
83 Correct 82 ms 49412 KB Output is correct
84 Correct 57 ms 49408 KB Output is correct
85 Correct 120 ms 49416 KB Output is correct
86 Correct 311 ms 49420 KB Output is correct
87 Correct 285 ms 49424 KB Output is correct
88 Correct 294 ms 49372 KB Output is correct
89 Incorrect 276 ms 49416 KB Output isn't correct
90 Halted 0 ms 0 KB -