Submission #711284

# Submission time Handle Problem Language Result Execution time Memory
711284 2023-03-16T13:26:37 Z kostia244 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
503 ms 102572 KB
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int N = 2525;
int n;
ll a, b, c;
ll dp[N][N], jump[N][N], best[N];
string s;
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> s >> a >> b >> c;

    vector<int> sa(n);
    iota(all(sa), 0);
    memset(jump, -1, sizeof jump);
    auto dfs = [&](auto self, vector<int> &p, int dep) -> void {
        if(p.size() < 2)
            return;
        vector<int> ch[26];
        int j = 0;
        for(auto i : p) {
            if(i + dep < s.size())
                ch[s[i + dep] - 'a'].push_back(i);
            if(dep) {
                while(p[j] + dep - 1 < i)
                    j++;
                jump[dep][i] = j ? p[j - 1] : -1;
            }
        }
        p.clear();
        for(int i = 0; i < 26; i++) {
            self(self, ch[i], dep + 1);
        }
    };
    dfs(dfs, sa, 0);

    for(int r = 0; r < n; r++) {
        memset(best, 0x3f, sizeof best);
        for(int l = r; l >= 0; l--) {//copy string
            best[l] = min(best[l], best[l + 1]);
            dp[r][l] = min((r > l ? dp[r - 1][l] : 0) + a, (r - l + 1) * a + best[l]);
            int lst = n + 1, len = r - l + 1, cnt = 0;
            for(int p = l; p >= 0; p = jump[len][p]) {
                // if(p + len - 1 < lst &&
                //      s.substr(p, len) == s.substr(l, len)) {
                    cnt++;
                    lst = p;
                    best[p] = min(best[p], (-len * a + c) * cnt + dp[r][l] + b);
                // }
            }
        }
    }
    cout << dp[n - 1][0] << '\n';
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:43:17: warning: variable 'lst' set but not used [-Wunused-but-set-variable]
   43 |             int lst = n + 1, len = r - l + 1, cnt = 0;
      |                 ^~~
copypaste3.cpp: In instantiation of 'main()::<lambda(auto:23, std::vector<int>&, int)> [with auto:23 = main()::<lambda(auto:23, std::vector<int>&, int)>]':
copypaste3.cpp:36:19:   required from here
copypaste3.cpp:23:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |             if(i + dep < s.size())
      |                ~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 50188 KB Output is correct
2 Correct 20 ms 50260 KB Output is correct
3 Correct 23 ms 50180 KB Output is correct
4 Correct 21 ms 50124 KB Output is correct
5 Correct 20 ms 50260 KB Output is correct
6 Correct 20 ms 50260 KB Output is correct
7 Correct 19 ms 50164 KB Output is correct
8 Correct 19 ms 50192 KB Output is correct
9 Correct 19 ms 50132 KB Output is correct
10 Correct 20 ms 50180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 50284 KB Output is correct
2 Correct 19 ms 50132 KB Output is correct
3 Correct 152 ms 81120 KB Output is correct
4 Correct 193 ms 85296 KB Output is correct
5 Correct 223 ms 90220 KB Output is correct
6 Correct 249 ms 96184 KB Output is correct
7 Correct 292 ms 102496 KB Output is correct
8 Correct 307 ms 102572 KB Output is correct
9 Correct 293 ms 102496 KB Output is correct
10 Correct 21 ms 50132 KB Output is correct
11 Correct 24 ms 50356 KB Output is correct
12 Correct 24 ms 50256 KB Output is correct
13 Correct 21 ms 50260 KB Output is correct
14 Correct 22 ms 50168 KB Output is correct
15 Correct 25 ms 50292 KB Output is correct
16 Correct 21 ms 50348 KB Output is correct
17 Correct 20 ms 50260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 50188 KB Output is correct
2 Correct 20 ms 50260 KB Output is correct
3 Correct 23 ms 50180 KB Output is correct
4 Correct 21 ms 50124 KB Output is correct
5 Correct 20 ms 50260 KB Output is correct
6 Correct 20 ms 50260 KB Output is correct
7 Correct 19 ms 50164 KB Output is correct
8 Correct 19 ms 50192 KB Output is correct
9 Correct 19 ms 50132 KB Output is correct
10 Correct 20 ms 50180 KB Output is correct
11 Correct 21 ms 50232 KB Output is correct
12 Correct 20 ms 50316 KB Output is correct
13 Correct 22 ms 50288 KB Output is correct
14 Correct 21 ms 50260 KB Output is correct
15 Correct 25 ms 50260 KB Output is correct
16 Correct 22 ms 50292 KB Output is correct
17 Correct 20 ms 50204 KB Output is correct
18 Correct 23 ms 50132 KB Output is correct
19 Correct 24 ms 50248 KB Output is correct
20 Correct 21 ms 50260 KB Output is correct
21 Correct 20 ms 50388 KB Output is correct
22 Correct 19 ms 50332 KB Output is correct
23 Correct 23 ms 50260 KB Output is correct
24 Correct 20 ms 50260 KB Output is correct
25 Correct 21 ms 50320 KB Output is correct
26 Correct 19 ms 50260 KB Output is correct
27 Correct 23 ms 50384 KB Output is correct
28 Correct 24 ms 50360 KB Output is correct
29 Correct 24 ms 50364 KB Output is correct
30 Correct 21 ms 50272 KB Output is correct
31 Correct 19 ms 50260 KB Output is correct
32 Correct 19 ms 50304 KB Output is correct
33 Correct 20 ms 50348 KB Output is correct
34 Correct 21 ms 50160 KB Output is correct
35 Correct 19 ms 50260 KB Output is correct
36 Correct 21 ms 50260 KB Output is correct
37 Correct 22 ms 50160 KB Output is correct
38 Correct 22 ms 50256 KB Output is correct
39 Correct 23 ms 50388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 50188 KB Output is correct
2 Correct 20 ms 50260 KB Output is correct
3 Correct 23 ms 50180 KB Output is correct
4 Correct 21 ms 50124 KB Output is correct
5 Correct 20 ms 50260 KB Output is correct
6 Correct 20 ms 50260 KB Output is correct
7 Correct 19 ms 50164 KB Output is correct
8 Correct 19 ms 50192 KB Output is correct
9 Correct 19 ms 50132 KB Output is correct
10 Correct 20 ms 50180 KB Output is correct
11 Correct 21 ms 50232 KB Output is correct
12 Correct 20 ms 50316 KB Output is correct
13 Correct 22 ms 50288 KB Output is correct
14 Correct 21 ms 50260 KB Output is correct
15 Correct 25 ms 50260 KB Output is correct
16 Correct 22 ms 50292 KB Output is correct
17 Correct 20 ms 50204 KB Output is correct
18 Correct 23 ms 50132 KB Output is correct
19 Correct 24 ms 50248 KB Output is correct
20 Correct 21 ms 50260 KB Output is correct
21 Correct 20 ms 50388 KB Output is correct
22 Correct 19 ms 50332 KB Output is correct
23 Correct 23 ms 50260 KB Output is correct
24 Correct 20 ms 50260 KB Output is correct
25 Correct 21 ms 50320 KB Output is correct
26 Correct 19 ms 50260 KB Output is correct
27 Correct 23 ms 50384 KB Output is correct
28 Correct 24 ms 50360 KB Output is correct
29 Correct 24 ms 50364 KB Output is correct
30 Correct 21 ms 50272 KB Output is correct
31 Correct 19 ms 50260 KB Output is correct
32 Correct 19 ms 50304 KB Output is correct
33 Correct 20 ms 50348 KB Output is correct
34 Correct 21 ms 50160 KB Output is correct
35 Correct 19 ms 50260 KB Output is correct
36 Correct 21 ms 50260 KB Output is correct
37 Correct 22 ms 50160 KB Output is correct
38 Correct 22 ms 50256 KB Output is correct
39 Correct 23 ms 50388 KB Output is correct
40 Correct 20 ms 50516 KB Output is correct
41 Correct 24 ms 51412 KB Output is correct
42 Correct 20 ms 51108 KB Output is correct
43 Correct 20 ms 51212 KB Output is correct
44 Correct 20 ms 51156 KB Output is correct
45 Correct 21 ms 51108 KB Output is correct
46 Correct 20 ms 51188 KB Output is correct
47 Correct 22 ms 51284 KB Output is correct
48 Correct 24 ms 51284 KB Output is correct
49 Correct 24 ms 51276 KB Output is correct
50 Correct 30 ms 51204 KB Output is correct
51 Correct 21 ms 51268 KB Output is correct
52 Correct 23 ms 51184 KB Output is correct
53 Correct 22 ms 51132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 50188 KB Output is correct
2 Correct 20 ms 50260 KB Output is correct
3 Correct 23 ms 50180 KB Output is correct
4 Correct 21 ms 50124 KB Output is correct
5 Correct 20 ms 50260 KB Output is correct
6 Correct 20 ms 50260 KB Output is correct
7 Correct 19 ms 50164 KB Output is correct
8 Correct 19 ms 50192 KB Output is correct
9 Correct 19 ms 50132 KB Output is correct
10 Correct 20 ms 50180 KB Output is correct
11 Correct 21 ms 50232 KB Output is correct
12 Correct 20 ms 50316 KB Output is correct
13 Correct 22 ms 50288 KB Output is correct
14 Correct 21 ms 50260 KB Output is correct
15 Correct 25 ms 50260 KB Output is correct
16 Correct 22 ms 50292 KB Output is correct
17 Correct 20 ms 50204 KB Output is correct
18 Correct 23 ms 50132 KB Output is correct
19 Correct 24 ms 50248 KB Output is correct
20 Correct 21 ms 50260 KB Output is correct
21 Correct 20 ms 50388 KB Output is correct
22 Correct 19 ms 50332 KB Output is correct
23 Correct 23 ms 50260 KB Output is correct
24 Correct 20 ms 50260 KB Output is correct
25 Correct 21 ms 50320 KB Output is correct
26 Correct 19 ms 50260 KB Output is correct
27 Correct 23 ms 50384 KB Output is correct
28 Correct 24 ms 50360 KB Output is correct
29 Correct 24 ms 50364 KB Output is correct
30 Correct 21 ms 50272 KB Output is correct
31 Correct 19 ms 50260 KB Output is correct
32 Correct 19 ms 50304 KB Output is correct
33 Correct 20 ms 50348 KB Output is correct
34 Correct 21 ms 50160 KB Output is correct
35 Correct 19 ms 50260 KB Output is correct
36 Correct 21 ms 50260 KB Output is correct
37 Correct 22 ms 50160 KB Output is correct
38 Correct 22 ms 50256 KB Output is correct
39 Correct 23 ms 50388 KB Output is correct
40 Correct 20 ms 50516 KB Output is correct
41 Correct 24 ms 51412 KB Output is correct
42 Correct 20 ms 51108 KB Output is correct
43 Correct 20 ms 51212 KB Output is correct
44 Correct 20 ms 51156 KB Output is correct
45 Correct 21 ms 51108 KB Output is correct
46 Correct 20 ms 51188 KB Output is correct
47 Correct 22 ms 51284 KB Output is correct
48 Correct 24 ms 51284 KB Output is correct
49 Correct 24 ms 51276 KB Output is correct
50 Correct 30 ms 51204 KB Output is correct
51 Correct 21 ms 51268 KB Output is correct
52 Correct 23 ms 51184 KB Output is correct
53 Correct 22 ms 51132 KB Output is correct
54 Correct 22 ms 52800 KB Output is correct
55 Correct 52 ms 61496 KB Output is correct
56 Correct 29 ms 58196 KB Output is correct
57 Correct 28 ms 58124 KB Output is correct
58 Correct 28 ms 58112 KB Output is correct
59 Correct 28 ms 58192 KB Output is correct
60 Correct 28 ms 58148 KB Output is correct
61 Correct 85 ms 58664 KB Output is correct
62 Correct 49 ms 59784 KB Output is correct
63 Correct 51 ms 58504 KB Output is correct
64 Correct 49 ms 58476 KB Output is correct
65 Correct 79 ms 58652 KB Output is correct
66 Correct 67 ms 58648 KB Output is correct
67 Correct 27 ms 58184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 50188 KB Output is correct
2 Correct 20 ms 50260 KB Output is correct
3 Correct 23 ms 50180 KB Output is correct
4 Correct 21 ms 50124 KB Output is correct
5 Correct 20 ms 50260 KB Output is correct
6 Correct 20 ms 50260 KB Output is correct
7 Correct 19 ms 50164 KB Output is correct
8 Correct 19 ms 50192 KB Output is correct
9 Correct 19 ms 50132 KB Output is correct
10 Correct 20 ms 50180 KB Output is correct
11 Correct 20 ms 50284 KB Output is correct
12 Correct 19 ms 50132 KB Output is correct
13 Correct 152 ms 81120 KB Output is correct
14 Correct 193 ms 85296 KB Output is correct
15 Correct 223 ms 90220 KB Output is correct
16 Correct 249 ms 96184 KB Output is correct
17 Correct 292 ms 102496 KB Output is correct
18 Correct 307 ms 102572 KB Output is correct
19 Correct 293 ms 102496 KB Output is correct
20 Correct 21 ms 50132 KB Output is correct
21 Correct 24 ms 50356 KB Output is correct
22 Correct 24 ms 50256 KB Output is correct
23 Correct 21 ms 50260 KB Output is correct
24 Correct 22 ms 50168 KB Output is correct
25 Correct 25 ms 50292 KB Output is correct
26 Correct 21 ms 50348 KB Output is correct
27 Correct 20 ms 50260 KB Output is correct
28 Correct 21 ms 50232 KB Output is correct
29 Correct 20 ms 50316 KB Output is correct
30 Correct 22 ms 50288 KB Output is correct
31 Correct 21 ms 50260 KB Output is correct
32 Correct 25 ms 50260 KB Output is correct
33 Correct 22 ms 50292 KB Output is correct
34 Correct 20 ms 50204 KB Output is correct
35 Correct 23 ms 50132 KB Output is correct
36 Correct 24 ms 50248 KB Output is correct
37 Correct 21 ms 50260 KB Output is correct
38 Correct 20 ms 50388 KB Output is correct
39 Correct 19 ms 50332 KB Output is correct
40 Correct 23 ms 50260 KB Output is correct
41 Correct 20 ms 50260 KB Output is correct
42 Correct 21 ms 50320 KB Output is correct
43 Correct 19 ms 50260 KB Output is correct
44 Correct 23 ms 50384 KB Output is correct
45 Correct 24 ms 50360 KB Output is correct
46 Correct 24 ms 50364 KB Output is correct
47 Correct 21 ms 50272 KB Output is correct
48 Correct 19 ms 50260 KB Output is correct
49 Correct 19 ms 50304 KB Output is correct
50 Correct 20 ms 50348 KB Output is correct
51 Correct 21 ms 50160 KB Output is correct
52 Correct 19 ms 50260 KB Output is correct
53 Correct 21 ms 50260 KB Output is correct
54 Correct 22 ms 50160 KB Output is correct
55 Correct 22 ms 50256 KB Output is correct
56 Correct 23 ms 50388 KB Output is correct
57 Correct 20 ms 50516 KB Output is correct
58 Correct 24 ms 51412 KB Output is correct
59 Correct 20 ms 51108 KB Output is correct
60 Correct 20 ms 51212 KB Output is correct
61 Correct 20 ms 51156 KB Output is correct
62 Correct 21 ms 51108 KB Output is correct
63 Correct 20 ms 51188 KB Output is correct
64 Correct 22 ms 51284 KB Output is correct
65 Correct 24 ms 51284 KB Output is correct
66 Correct 24 ms 51276 KB Output is correct
67 Correct 30 ms 51204 KB Output is correct
68 Correct 21 ms 51268 KB Output is correct
69 Correct 23 ms 51184 KB Output is correct
70 Correct 22 ms 51132 KB Output is correct
71 Correct 22 ms 52800 KB Output is correct
72 Correct 52 ms 61496 KB Output is correct
73 Correct 29 ms 58196 KB Output is correct
74 Correct 28 ms 58124 KB Output is correct
75 Correct 28 ms 58112 KB Output is correct
76 Correct 28 ms 58192 KB Output is correct
77 Correct 28 ms 58148 KB Output is correct
78 Correct 85 ms 58664 KB Output is correct
79 Correct 49 ms 59784 KB Output is correct
80 Correct 51 ms 58504 KB Output is correct
81 Correct 49 ms 58476 KB Output is correct
82 Correct 79 ms 58652 KB Output is correct
83 Correct 67 ms 58648 KB Output is correct
84 Correct 27 ms 58184 KB Output is correct
85 Correct 47 ms 66400 KB Output is correct
86 Correct 88 ms 83872 KB Output is correct
87 Correct 79 ms 83788 KB Output is correct
88 Correct 74 ms 83832 KB Output is correct
89 Correct 70 ms 83784 KB Output is correct
90 Correct 63 ms 83824 KB Output is correct
91 Correct 303 ms 85904 KB Output is correct
92 Correct 278 ms 87100 KB Output is correct
93 Correct 301 ms 84720 KB Output is correct
94 Correct 232 ms 84428 KB Output is correct
95 Correct 482 ms 85136 KB Output is correct
96 Correct 503 ms 85196 KB Output is correct
97 Correct 75 ms 83920 KB Output is correct