Submission #1061878

# Submission time Handle Problem Language Result Execution time Memory
1061878 2024-08-16T14:42:49 Z sleepntsheep Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
216 ms 98668 KB
#pragma GCC optimize("O3,unroll-loops")

#include <deque>
#include <string>
#include <iostream>
#include <map>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
template <typename T>
using ve = vector<T>;
template <typename T>
using bs = basic_string<T>;

const int N = 2505;

int n, nxt[N][N + N], z[N];

void do_z(char *s, int n) {
    for (int i = 0; i < n; ++i) z[i] = 0;
    z[0] = n;
    for (int i = 1, l {}, r { 1 }; i < n; ++i) {
        if (i < r) z[i] = min(z[i - l], r - i);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
        if (i + z[i] > r) l = i, r = i + z[i];
    }
}

ll dp[N][N], a, b, c;
char s[N];

void init() {
    memset(dp, 63, sizeof dp);
    memset(nxt, 63, sizeof nxt);

    for (int i = 1; i <= n; ++i)
        dp[i][i] = a;

    for (int i = 1; i <= n; ++i) {
        do_z(s + i, n - i + 1);
        for (int p = i, j = i; j <= n; ++j) {
            while (p <= n && (p <= j || z[p - i] < j - i + 1)) ++p;
            nxt[i][j] = p;
        }
    }
}

int main() {
    scanf("%d%s%lld%lld%lld", &n, s + 1, &a, &b, &c);

    init();

    for (int l = 1; l <= n; ++l) {
        for (int i = 1, j = l; j <= n; ++i, ++j) {
            dp[i][j] = min(dp[i][j], dp[i + 1][j] + a);
            dp[i][j] = min(dp[i][j], dp[i][j - 1] + a);
            for (int at = i, cnt = 1; at <= n; ++cnt, at = nxt[at][at + l - 1]) {
                int jj = at + l - 1;
                dp[i][jj] = min(dp[i][jj], dp[i][j] + b + cnt * c + (jj - i + 1 - cnt * l) * a);
            }
        }
    }

    printf("%lld", dp[1][n]);
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d%s%lld%lld%lld", &n, s + 1, &a, &b, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 98648 KB Output is correct
2 Correct 22 ms 98648 KB Output is correct
3 Correct 27 ms 98460 KB Output is correct
4 Correct 24 ms 98648 KB Output is correct
5 Correct 22 ms 98648 KB Output is correct
6 Correct 22 ms 98652 KB Output is correct
7 Correct 24 ms 98652 KB Output is correct
8 Correct 24 ms 98560 KB Output is correct
9 Correct 27 ms 98572 KB Output is correct
10 Correct 21 ms 98648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 98644 KB Output is correct
2 Correct 21 ms 98652 KB Output is correct
3 Correct 90 ms 98476 KB Output is correct
4 Correct 106 ms 98656 KB Output is correct
5 Correct 130 ms 98652 KB Output is correct
6 Correct 158 ms 98652 KB Output is correct
7 Correct 193 ms 98652 KB Output is correct
8 Correct 216 ms 98648 KB Output is correct
9 Correct 175 ms 98652 KB Output is correct
10 Correct 21 ms 98644 KB Output is correct
11 Correct 22 ms 98652 KB Output is correct
12 Correct 25 ms 98460 KB Output is correct
13 Correct 25 ms 98652 KB Output is correct
14 Correct 22 ms 98656 KB Output is correct
15 Correct 22 ms 98440 KB Output is correct
16 Correct 30 ms 98644 KB Output is correct
17 Correct 25 ms 98652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 98648 KB Output is correct
2 Correct 22 ms 98648 KB Output is correct
3 Correct 27 ms 98460 KB Output is correct
4 Correct 24 ms 98648 KB Output is correct
5 Correct 22 ms 98648 KB Output is correct
6 Correct 22 ms 98652 KB Output is correct
7 Correct 24 ms 98652 KB Output is correct
8 Correct 24 ms 98560 KB Output is correct
9 Correct 27 ms 98572 KB Output is correct
10 Correct 21 ms 98648 KB Output is correct
11 Correct 23 ms 98640 KB Output is correct
12 Correct 22 ms 98644 KB Output is correct
13 Correct 23 ms 98492 KB Output is correct
14 Correct 24 ms 98652 KB Output is correct
15 Correct 23 ms 98652 KB Output is correct
16 Correct 23 ms 98648 KB Output is correct
17 Correct 22 ms 98668 KB Output is correct
18 Correct 24 ms 98652 KB Output is correct
19 Correct 25 ms 98648 KB Output is correct
20 Correct 23 ms 98652 KB Output is correct
21 Correct 23 ms 98640 KB Output is correct
22 Correct 25 ms 98640 KB Output is correct
23 Correct 22 ms 98644 KB Output is correct
24 Correct 22 ms 98640 KB Output is correct
25 Correct 21 ms 98652 KB Output is correct
26 Correct 21 ms 98660 KB Output is correct
27 Correct 22 ms 98648 KB Output is correct
28 Correct 27 ms 98640 KB Output is correct
29 Correct 28 ms 98632 KB Output is correct
30 Correct 23 ms 98564 KB Output is correct
31 Correct 25 ms 98508 KB Output is correct
32 Correct 21 ms 98476 KB Output is correct
33 Correct 25 ms 98616 KB Output is correct
34 Correct 24 ms 98652 KB Output is correct
35 Correct 24 ms 98652 KB Output is correct
36 Correct 24 ms 98652 KB Output is correct
37 Correct 23 ms 98480 KB Output is correct
38 Correct 24 ms 98652 KB Output is correct
39 Correct 22 ms 98652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 98648 KB Output is correct
2 Correct 22 ms 98648 KB Output is correct
3 Correct 27 ms 98460 KB Output is correct
4 Correct 24 ms 98648 KB Output is correct
5 Correct 22 ms 98648 KB Output is correct
6 Correct 22 ms 98652 KB Output is correct
7 Correct 24 ms 98652 KB Output is correct
8 Correct 24 ms 98560 KB Output is correct
9 Correct 27 ms 98572 KB Output is correct
10 Correct 21 ms 98648 KB Output is correct
11 Correct 23 ms 98640 KB Output is correct
12 Correct 22 ms 98644 KB Output is correct
13 Correct 23 ms 98492 KB Output is correct
14 Correct 24 ms 98652 KB Output is correct
15 Correct 23 ms 98652 KB Output is correct
16 Correct 23 ms 98648 KB Output is correct
17 Correct 22 ms 98668 KB Output is correct
18 Correct 24 ms 98652 KB Output is correct
19 Correct 25 ms 98648 KB Output is correct
20 Correct 23 ms 98652 KB Output is correct
21 Correct 23 ms 98640 KB Output is correct
22 Correct 25 ms 98640 KB Output is correct
23 Correct 22 ms 98644 KB Output is correct
24 Correct 22 ms 98640 KB Output is correct
25 Correct 21 ms 98652 KB Output is correct
26 Correct 21 ms 98660 KB Output is correct
27 Correct 22 ms 98648 KB Output is correct
28 Correct 27 ms 98640 KB Output is correct
29 Correct 28 ms 98632 KB Output is correct
30 Correct 23 ms 98564 KB Output is correct
31 Correct 25 ms 98508 KB Output is correct
32 Correct 21 ms 98476 KB Output is correct
33 Correct 25 ms 98616 KB Output is correct
34 Correct 24 ms 98652 KB Output is correct
35 Correct 24 ms 98652 KB Output is correct
36 Correct 24 ms 98652 KB Output is correct
37 Correct 23 ms 98480 KB Output is correct
38 Correct 24 ms 98652 KB Output is correct
39 Correct 22 ms 98652 KB Output is correct
40 Correct 23 ms 98652 KB Output is correct
41 Correct 23 ms 98648 KB Output is correct
42 Correct 21 ms 98512 KB Output is correct
43 Correct 23 ms 98652 KB Output is correct
44 Correct 22 ms 98652 KB Output is correct
45 Correct 22 ms 98652 KB Output is correct
46 Correct 22 ms 98608 KB Output is correct
47 Correct 22 ms 98448 KB Output is correct
48 Correct 22 ms 98652 KB Output is correct
49 Correct 23 ms 98648 KB Output is correct
50 Correct 21 ms 98652 KB Output is correct
51 Correct 24 ms 98632 KB Output is correct
52 Correct 22 ms 98652 KB Output is correct
53 Correct 22 ms 98616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 98648 KB Output is correct
2 Correct 22 ms 98648 KB Output is correct
3 Correct 27 ms 98460 KB Output is correct
4 Correct 24 ms 98648 KB Output is correct
5 Correct 22 ms 98648 KB Output is correct
6 Correct 22 ms 98652 KB Output is correct
7 Correct 24 ms 98652 KB Output is correct
8 Correct 24 ms 98560 KB Output is correct
9 Correct 27 ms 98572 KB Output is correct
10 Correct 21 ms 98648 KB Output is correct
11 Correct 23 ms 98640 KB Output is correct
12 Correct 22 ms 98644 KB Output is correct
13 Correct 23 ms 98492 KB Output is correct
14 Correct 24 ms 98652 KB Output is correct
15 Correct 23 ms 98652 KB Output is correct
16 Correct 23 ms 98648 KB Output is correct
17 Correct 22 ms 98668 KB Output is correct
18 Correct 24 ms 98652 KB Output is correct
19 Correct 25 ms 98648 KB Output is correct
20 Correct 23 ms 98652 KB Output is correct
21 Correct 23 ms 98640 KB Output is correct
22 Correct 25 ms 98640 KB Output is correct
23 Correct 22 ms 98644 KB Output is correct
24 Correct 22 ms 98640 KB Output is correct
25 Correct 21 ms 98652 KB Output is correct
26 Correct 21 ms 98660 KB Output is correct
27 Correct 22 ms 98648 KB Output is correct
28 Correct 27 ms 98640 KB Output is correct
29 Correct 28 ms 98632 KB Output is correct
30 Correct 23 ms 98564 KB Output is correct
31 Correct 25 ms 98508 KB Output is correct
32 Correct 21 ms 98476 KB Output is correct
33 Correct 25 ms 98616 KB Output is correct
34 Correct 24 ms 98652 KB Output is correct
35 Correct 24 ms 98652 KB Output is correct
36 Correct 24 ms 98652 KB Output is correct
37 Correct 23 ms 98480 KB Output is correct
38 Correct 24 ms 98652 KB Output is correct
39 Correct 22 ms 98652 KB Output is correct
40 Correct 23 ms 98652 KB Output is correct
41 Correct 23 ms 98648 KB Output is correct
42 Correct 21 ms 98512 KB Output is correct
43 Correct 23 ms 98652 KB Output is correct
44 Correct 22 ms 98652 KB Output is correct
45 Correct 22 ms 98652 KB Output is correct
46 Correct 22 ms 98608 KB Output is correct
47 Correct 22 ms 98448 KB Output is correct
48 Correct 22 ms 98652 KB Output is correct
49 Correct 23 ms 98648 KB Output is correct
50 Correct 21 ms 98652 KB Output is correct
51 Correct 24 ms 98632 KB Output is correct
52 Correct 22 ms 98652 KB Output is correct
53 Correct 22 ms 98616 KB Output is correct
54 Correct 25 ms 98652 KB Output is correct
55 Correct 40 ms 98652 KB Output is correct
56 Correct 31 ms 98448 KB Output is correct
57 Correct 32 ms 98652 KB Output is correct
58 Correct 29 ms 98652 KB Output is correct
59 Correct 31 ms 98652 KB Output is correct
60 Correct 27 ms 98500 KB Output is correct
61 Correct 28 ms 98648 KB Output is correct
62 Correct 38 ms 98652 KB Output is correct
63 Correct 28 ms 98520 KB Output is correct
64 Correct 28 ms 98648 KB Output is correct
65 Correct 35 ms 98652 KB Output is correct
66 Correct 35 ms 98640 KB Output is correct
67 Correct 29 ms 98648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 98648 KB Output is correct
2 Correct 22 ms 98648 KB Output is correct
3 Correct 27 ms 98460 KB Output is correct
4 Correct 24 ms 98648 KB Output is correct
5 Correct 22 ms 98648 KB Output is correct
6 Correct 22 ms 98652 KB Output is correct
7 Correct 24 ms 98652 KB Output is correct
8 Correct 24 ms 98560 KB Output is correct
9 Correct 27 ms 98572 KB Output is correct
10 Correct 21 ms 98648 KB Output is correct
11 Correct 22 ms 98644 KB Output is correct
12 Correct 21 ms 98652 KB Output is correct
13 Correct 90 ms 98476 KB Output is correct
14 Correct 106 ms 98656 KB Output is correct
15 Correct 130 ms 98652 KB Output is correct
16 Correct 158 ms 98652 KB Output is correct
17 Correct 193 ms 98652 KB Output is correct
18 Correct 216 ms 98648 KB Output is correct
19 Correct 175 ms 98652 KB Output is correct
20 Correct 21 ms 98644 KB Output is correct
21 Correct 22 ms 98652 KB Output is correct
22 Correct 25 ms 98460 KB Output is correct
23 Correct 25 ms 98652 KB Output is correct
24 Correct 22 ms 98656 KB Output is correct
25 Correct 22 ms 98440 KB Output is correct
26 Correct 30 ms 98644 KB Output is correct
27 Correct 25 ms 98652 KB Output is correct
28 Correct 23 ms 98640 KB Output is correct
29 Correct 22 ms 98644 KB Output is correct
30 Correct 23 ms 98492 KB Output is correct
31 Correct 24 ms 98652 KB Output is correct
32 Correct 23 ms 98652 KB Output is correct
33 Correct 23 ms 98648 KB Output is correct
34 Correct 22 ms 98668 KB Output is correct
35 Correct 24 ms 98652 KB Output is correct
36 Correct 25 ms 98648 KB Output is correct
37 Correct 23 ms 98652 KB Output is correct
38 Correct 23 ms 98640 KB Output is correct
39 Correct 25 ms 98640 KB Output is correct
40 Correct 22 ms 98644 KB Output is correct
41 Correct 22 ms 98640 KB Output is correct
42 Correct 21 ms 98652 KB Output is correct
43 Correct 21 ms 98660 KB Output is correct
44 Correct 22 ms 98648 KB Output is correct
45 Correct 27 ms 98640 KB Output is correct
46 Correct 28 ms 98632 KB Output is correct
47 Correct 23 ms 98564 KB Output is correct
48 Correct 25 ms 98508 KB Output is correct
49 Correct 21 ms 98476 KB Output is correct
50 Correct 25 ms 98616 KB Output is correct
51 Correct 24 ms 98652 KB Output is correct
52 Correct 24 ms 98652 KB Output is correct
53 Correct 24 ms 98652 KB Output is correct
54 Correct 23 ms 98480 KB Output is correct
55 Correct 24 ms 98652 KB Output is correct
56 Correct 22 ms 98652 KB Output is correct
57 Correct 23 ms 98652 KB Output is correct
58 Correct 23 ms 98648 KB Output is correct
59 Correct 21 ms 98512 KB Output is correct
60 Correct 23 ms 98652 KB Output is correct
61 Correct 22 ms 98652 KB Output is correct
62 Correct 22 ms 98652 KB Output is correct
63 Correct 22 ms 98608 KB Output is correct
64 Correct 22 ms 98448 KB Output is correct
65 Correct 22 ms 98652 KB Output is correct
66 Correct 23 ms 98648 KB Output is correct
67 Correct 21 ms 98652 KB Output is correct
68 Correct 24 ms 98632 KB Output is correct
69 Correct 22 ms 98652 KB Output is correct
70 Correct 22 ms 98616 KB Output is correct
71 Correct 25 ms 98652 KB Output is correct
72 Correct 40 ms 98652 KB Output is correct
73 Correct 31 ms 98448 KB Output is correct
74 Correct 32 ms 98652 KB Output is correct
75 Correct 29 ms 98652 KB Output is correct
76 Correct 31 ms 98652 KB Output is correct
77 Correct 27 ms 98500 KB Output is correct
78 Correct 28 ms 98648 KB Output is correct
79 Correct 38 ms 98652 KB Output is correct
80 Correct 28 ms 98520 KB Output is correct
81 Correct 28 ms 98648 KB Output is correct
82 Correct 35 ms 98652 KB Output is correct
83 Correct 35 ms 98640 KB Output is correct
84 Correct 29 ms 98648 KB Output is correct
85 Correct 44 ms 98660 KB Output is correct
86 Correct 94 ms 98660 KB Output is correct
87 Correct 91 ms 98652 KB Output is correct
88 Correct 79 ms 98652 KB Output is correct
89 Correct 60 ms 98652 KB Output is correct
90 Correct 62 ms 98516 KB Output is correct
91 Correct 120 ms 98600 KB Output is correct
92 Correct 149 ms 98652 KB Output is correct
93 Correct 66 ms 98652 KB Output is correct
94 Correct 74 ms 98652 KB Output is correct
95 Correct 165 ms 98652 KB Output is correct
96 Correct 170 ms 98656 KB Output is correct
97 Correct 54 ms 98652 KB Output is correct