Submission #1061882

# Submission time Handle Problem Language Result Execution time Memory
1061882 2024-08-16T14:44:03 Z sleepntsheep Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
174 ms 69784 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], 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);

    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) {
            if (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:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     scanf("%d%s%lld%lld%lld", &n, s + 1, &a, &b, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 49496 KB Output is correct
2 Correct 6 ms 49500 KB Output is correct
3 Correct 6 ms 49500 KB Output is correct
4 Correct 6 ms 49500 KB Output is correct
5 Correct 6 ms 49500 KB Output is correct
6 Correct 6 ms 49500 KB Output is correct
7 Correct 6 ms 49756 KB Output is correct
8 Correct 5 ms 49800 KB Output is correct
9 Correct 6 ms 49756 KB Output is correct
10 Correct 5 ms 49816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 49752 KB Output is correct
2 Correct 6 ms 49756 KB Output is correct
3 Correct 81 ms 63064 KB Output is correct
4 Correct 91 ms 64604 KB Output is correct
5 Correct 107 ms 66232 KB Output is correct
6 Correct 128 ms 67932 KB Output is correct
7 Correct 168 ms 69716 KB Output is correct
8 Correct 174 ms 69780 KB Output is correct
9 Correct 170 ms 69776 KB Output is correct
10 Correct 6 ms 49756 KB Output is correct
11 Correct 5 ms 49756 KB Output is correct
12 Correct 5 ms 49756 KB Output is correct
13 Correct 5 ms 49756 KB Output is correct
14 Correct 5 ms 49756 KB Output is correct
15 Correct 5 ms 49752 KB Output is correct
16 Correct 5 ms 49784 KB Output is correct
17 Correct 6 ms 49752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 49496 KB Output is correct
2 Correct 6 ms 49500 KB Output is correct
3 Correct 6 ms 49500 KB Output is correct
4 Correct 6 ms 49500 KB Output is correct
5 Correct 6 ms 49500 KB Output is correct
6 Correct 6 ms 49500 KB Output is correct
7 Correct 6 ms 49756 KB Output is correct
8 Correct 5 ms 49800 KB Output is correct
9 Correct 6 ms 49756 KB Output is correct
10 Correct 5 ms 49816 KB Output is correct
11 Correct 5 ms 49756 KB Output is correct
12 Correct 5 ms 49752 KB Output is correct
13 Correct 6 ms 49756 KB Output is correct
14 Correct 5 ms 49756 KB Output is correct
15 Correct 5 ms 49756 KB Output is correct
16 Correct 5 ms 49756 KB Output is correct
17 Correct 5 ms 49756 KB Output is correct
18 Correct 5 ms 49756 KB Output is correct
19 Correct 5 ms 49756 KB Output is correct
20 Correct 6 ms 49756 KB Output is correct
21 Correct 5 ms 49812 KB Output is correct
22 Correct 6 ms 49756 KB Output is correct
23 Correct 5 ms 49800 KB Output is correct
24 Correct 6 ms 49752 KB Output is correct
25 Correct 6 ms 49796 KB Output is correct
26 Correct 6 ms 49756 KB Output is correct
27 Correct 6 ms 49752 KB Output is correct
28 Correct 5 ms 49752 KB Output is correct
29 Correct 5 ms 49756 KB Output is correct
30 Correct 6 ms 49752 KB Output is correct
31 Correct 5 ms 49820 KB Output is correct
32 Correct 5 ms 49756 KB Output is correct
33 Correct 6 ms 49752 KB Output is correct
34 Correct 5 ms 49752 KB Output is correct
35 Correct 6 ms 49500 KB Output is correct
36 Correct 5 ms 49756 KB Output is correct
37 Correct 5 ms 49756 KB Output is correct
38 Correct 5 ms 49756 KB Output is correct
39 Correct 5 ms 49840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 49496 KB Output is correct
2 Correct 6 ms 49500 KB Output is correct
3 Correct 6 ms 49500 KB Output is correct
4 Correct 6 ms 49500 KB Output is correct
5 Correct 6 ms 49500 KB Output is correct
6 Correct 6 ms 49500 KB Output is correct
7 Correct 6 ms 49756 KB Output is correct
8 Correct 5 ms 49800 KB Output is correct
9 Correct 6 ms 49756 KB Output is correct
10 Correct 5 ms 49816 KB Output is correct
11 Correct 5 ms 49756 KB Output is correct
12 Correct 5 ms 49752 KB Output is correct
13 Correct 6 ms 49756 KB Output is correct
14 Correct 5 ms 49756 KB Output is correct
15 Correct 5 ms 49756 KB Output is correct
16 Correct 5 ms 49756 KB Output is correct
17 Correct 5 ms 49756 KB Output is correct
18 Correct 5 ms 49756 KB Output is correct
19 Correct 5 ms 49756 KB Output is correct
20 Correct 6 ms 49756 KB Output is correct
21 Correct 5 ms 49812 KB Output is correct
22 Correct 6 ms 49756 KB Output is correct
23 Correct 5 ms 49800 KB Output is correct
24 Correct 6 ms 49752 KB Output is correct
25 Correct 6 ms 49796 KB Output is correct
26 Correct 6 ms 49756 KB Output is correct
27 Correct 6 ms 49752 KB Output is correct
28 Correct 5 ms 49752 KB Output is correct
29 Correct 5 ms 49756 KB Output is correct
30 Correct 6 ms 49752 KB Output is correct
31 Correct 5 ms 49820 KB Output is correct
32 Correct 5 ms 49756 KB Output is correct
33 Correct 6 ms 49752 KB Output is correct
34 Correct 5 ms 49752 KB Output is correct
35 Correct 6 ms 49500 KB Output is correct
36 Correct 5 ms 49756 KB Output is correct
37 Correct 5 ms 49756 KB Output is correct
38 Correct 5 ms 49756 KB Output is correct
39 Correct 5 ms 49840 KB Output is correct
40 Correct 6 ms 50012 KB Output is correct
41 Correct 6 ms 50520 KB Output is correct
42 Correct 6 ms 50524 KB Output is correct
43 Correct 6 ms 50524 KB Output is correct
44 Correct 6 ms 50524 KB Output is correct
45 Correct 6 ms 50524 KB Output is correct
46 Correct 7 ms 50368 KB Output is correct
47 Correct 6 ms 51804 KB Output is correct
48 Correct 6 ms 50524 KB Output is correct
49 Correct 6 ms 51804 KB Output is correct
50 Correct 6 ms 51804 KB Output is correct
51 Correct 6 ms 50524 KB Output is correct
52 Correct 7 ms 50524 KB Output is correct
53 Correct 6 ms 50556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 49496 KB Output is correct
2 Correct 6 ms 49500 KB Output is correct
3 Correct 6 ms 49500 KB Output is correct
4 Correct 6 ms 49500 KB Output is correct
5 Correct 6 ms 49500 KB Output is correct
6 Correct 6 ms 49500 KB Output is correct
7 Correct 6 ms 49756 KB Output is correct
8 Correct 5 ms 49800 KB Output is correct
9 Correct 6 ms 49756 KB Output is correct
10 Correct 5 ms 49816 KB Output is correct
11 Correct 5 ms 49756 KB Output is correct
12 Correct 5 ms 49752 KB Output is correct
13 Correct 6 ms 49756 KB Output is correct
14 Correct 5 ms 49756 KB Output is correct
15 Correct 5 ms 49756 KB Output is correct
16 Correct 5 ms 49756 KB Output is correct
17 Correct 5 ms 49756 KB Output is correct
18 Correct 5 ms 49756 KB Output is correct
19 Correct 5 ms 49756 KB Output is correct
20 Correct 6 ms 49756 KB Output is correct
21 Correct 5 ms 49812 KB Output is correct
22 Correct 6 ms 49756 KB Output is correct
23 Correct 5 ms 49800 KB Output is correct
24 Correct 6 ms 49752 KB Output is correct
25 Correct 6 ms 49796 KB Output is correct
26 Correct 6 ms 49756 KB Output is correct
27 Correct 6 ms 49752 KB Output is correct
28 Correct 5 ms 49752 KB Output is correct
29 Correct 5 ms 49756 KB Output is correct
30 Correct 6 ms 49752 KB Output is correct
31 Correct 5 ms 49820 KB Output is correct
32 Correct 5 ms 49756 KB Output is correct
33 Correct 6 ms 49752 KB Output is correct
34 Correct 5 ms 49752 KB Output is correct
35 Correct 6 ms 49500 KB Output is correct
36 Correct 5 ms 49756 KB Output is correct
37 Correct 5 ms 49756 KB Output is correct
38 Correct 5 ms 49756 KB Output is correct
39 Correct 5 ms 49840 KB Output is correct
40 Correct 6 ms 50012 KB Output is correct
41 Correct 6 ms 50520 KB Output is correct
42 Correct 6 ms 50524 KB Output is correct
43 Correct 6 ms 50524 KB Output is correct
44 Correct 6 ms 50524 KB Output is correct
45 Correct 6 ms 50524 KB Output is correct
46 Correct 7 ms 50368 KB Output is correct
47 Correct 6 ms 51804 KB Output is correct
48 Correct 6 ms 50524 KB Output is correct
49 Correct 6 ms 51804 KB Output is correct
50 Correct 6 ms 51804 KB Output is correct
51 Correct 6 ms 50524 KB Output is correct
52 Correct 7 ms 50524 KB Output is correct
53 Correct 6 ms 50556 KB Output is correct
54 Correct 9 ms 51804 KB Output is correct
55 Correct 25 ms 55900 KB Output is correct
56 Correct 16 ms 55900 KB Output is correct
57 Correct 14 ms 55900 KB Output is correct
58 Correct 13 ms 55388 KB Output is correct
59 Correct 12 ms 55388 KB Output is correct
60 Correct 11 ms 55976 KB Output is correct
61 Correct 14 ms 55608 KB Output is correct
62 Correct 23 ms 55900 KB Output is correct
63 Correct 14 ms 55896 KB Output is correct
64 Correct 14 ms 56112 KB Output is correct
65 Correct 22 ms 55388 KB Output is correct
66 Correct 21 ms 55896 KB Output is correct
67 Correct 12 ms 55900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 49496 KB Output is correct
2 Correct 6 ms 49500 KB Output is correct
3 Correct 6 ms 49500 KB Output is correct
4 Correct 6 ms 49500 KB Output is correct
5 Correct 6 ms 49500 KB Output is correct
6 Correct 6 ms 49500 KB Output is correct
7 Correct 6 ms 49756 KB Output is correct
8 Correct 5 ms 49800 KB Output is correct
9 Correct 6 ms 49756 KB Output is correct
10 Correct 5 ms 49816 KB Output is correct
11 Correct 6 ms 49752 KB Output is correct
12 Correct 6 ms 49756 KB Output is correct
13 Correct 81 ms 63064 KB Output is correct
14 Correct 91 ms 64604 KB Output is correct
15 Correct 107 ms 66232 KB Output is correct
16 Correct 128 ms 67932 KB Output is correct
17 Correct 168 ms 69716 KB Output is correct
18 Correct 174 ms 69780 KB Output is correct
19 Correct 170 ms 69776 KB Output is correct
20 Correct 6 ms 49756 KB Output is correct
21 Correct 5 ms 49756 KB Output is correct
22 Correct 5 ms 49756 KB Output is correct
23 Correct 5 ms 49756 KB Output is correct
24 Correct 5 ms 49756 KB Output is correct
25 Correct 5 ms 49752 KB Output is correct
26 Correct 5 ms 49784 KB Output is correct
27 Correct 6 ms 49752 KB Output is correct
28 Correct 5 ms 49756 KB Output is correct
29 Correct 5 ms 49752 KB Output is correct
30 Correct 6 ms 49756 KB Output is correct
31 Correct 5 ms 49756 KB Output is correct
32 Correct 5 ms 49756 KB Output is correct
33 Correct 5 ms 49756 KB Output is correct
34 Correct 5 ms 49756 KB Output is correct
35 Correct 5 ms 49756 KB Output is correct
36 Correct 5 ms 49756 KB Output is correct
37 Correct 6 ms 49756 KB Output is correct
38 Correct 5 ms 49812 KB Output is correct
39 Correct 6 ms 49756 KB Output is correct
40 Correct 5 ms 49800 KB Output is correct
41 Correct 6 ms 49752 KB Output is correct
42 Correct 6 ms 49796 KB Output is correct
43 Correct 6 ms 49756 KB Output is correct
44 Correct 6 ms 49752 KB Output is correct
45 Correct 5 ms 49752 KB Output is correct
46 Correct 5 ms 49756 KB Output is correct
47 Correct 6 ms 49752 KB Output is correct
48 Correct 5 ms 49820 KB Output is correct
49 Correct 5 ms 49756 KB Output is correct
50 Correct 6 ms 49752 KB Output is correct
51 Correct 5 ms 49752 KB Output is correct
52 Correct 6 ms 49500 KB Output is correct
53 Correct 5 ms 49756 KB Output is correct
54 Correct 5 ms 49756 KB Output is correct
55 Correct 5 ms 49756 KB Output is correct
56 Correct 5 ms 49840 KB Output is correct
57 Correct 6 ms 50012 KB Output is correct
58 Correct 6 ms 50520 KB Output is correct
59 Correct 6 ms 50524 KB Output is correct
60 Correct 6 ms 50524 KB Output is correct
61 Correct 6 ms 50524 KB Output is correct
62 Correct 6 ms 50524 KB Output is correct
63 Correct 7 ms 50368 KB Output is correct
64 Correct 6 ms 51804 KB Output is correct
65 Correct 6 ms 50524 KB Output is correct
66 Correct 6 ms 51804 KB Output is correct
67 Correct 6 ms 51804 KB Output is correct
68 Correct 6 ms 50524 KB Output is correct
69 Correct 7 ms 50524 KB Output is correct
70 Correct 6 ms 50556 KB Output is correct
71 Correct 9 ms 51804 KB Output is correct
72 Correct 25 ms 55900 KB Output is correct
73 Correct 16 ms 55900 KB Output is correct
74 Correct 14 ms 55900 KB Output is correct
75 Correct 13 ms 55388 KB Output is correct
76 Correct 12 ms 55388 KB Output is correct
77 Correct 11 ms 55976 KB Output is correct
78 Correct 14 ms 55608 KB Output is correct
79 Correct 23 ms 55900 KB Output is correct
80 Correct 14 ms 55896 KB Output is correct
81 Correct 14 ms 56112 KB Output is correct
82 Correct 22 ms 55388 KB Output is correct
83 Correct 21 ms 55896 KB Output is correct
84 Correct 12 ms 55900 KB Output is correct
85 Correct 39 ms 60760 KB Output is correct
86 Correct 82 ms 69748 KB Output is correct
87 Correct 73 ms 69712 KB Output is correct
88 Correct 53 ms 69724 KB Output is correct
89 Correct 45 ms 69536 KB Output is correct
90 Correct 43 ms 69720 KB Output is correct
91 Correct 120 ms 69784 KB Output is correct
92 Correct 132 ms 69716 KB Output is correct
93 Correct 64 ms 69776 KB Output is correct
94 Correct 74 ms 69724 KB Output is correct
95 Correct 154 ms 69780 KB Output is correct
96 Correct 154 ms 69780 KB Output is correct
97 Correct 44 ms 69720 KB Output is correct