Submission #1038707

# Submission time Handle Problem Language Result Execution time Memory
1038707 2024-07-30T06:38:07 Z juicy Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
353 ms 123312 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 2505;

int n, A, B, C;
int sa[N], lcp[N], nxt[N][N];
long long dp[N][N], g[N][N];
string s;

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> s >> A >> B >> C;
  s = '&' + s;
  iota(sa + 1, sa + n + 1, 1);
  sort(sa + 1, sa + n + 1, [&](int i, int j) {
    return s.substr(i) < s.substr(j);
  });
  for (int i = 1; i < n; ++i) {
    int u = sa[i], v = sa[i + 1];
    while (u + lcp[i] <= n && v + lcp[i] <= n && s[u + lcp[i]] == s[v + lcp[i]]) {
      ++lcp[i];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ) {
      int k = j;
      while (lcp[k] >= i) {
        ++k;
      }
      vector<int> cands;
      while (j <= k) {
        cands.push_back(sa[j++]);
      }
      sort(cands.rbegin(), cands.rend());
      k = -1;
      for (int u : cands) {
        while (k + 1 < cands.size() && cands[k + 1] - u >= i) {
          ++k;
        }
        nxt[u][i] = k == -1 ? k : cands[k];
      }
    }
  }
  memset(dp, 0x3f, sizeof(dp));
  memset(g, 0x3f, sizeof(g));
  for (int i = 1; i <= n; ++i) {
    dp[i][i] = A;
  }
  for (int l = 1; l <= n; ++l) {
    for (int i = 1, j = l; j <= n; ++i, ++j) {
      auto &cur = dp[i][j];
      cur = min(cur, g[i][j]);
      dp[i][j + 1] = min(dp[i][j + 1], cur + A);
      int st = i, cnt = 0, sz = 0;
      while (1) {
        int ed = st + l - 1;
        ++cnt;
        sz += l;
        g[i][ed] = min(g[i][ed], (long long) (ed - i + 1 - sz) * A + B + (long long) C * cnt + cur);
        if (nxt[st][l] == -1) {
          break;
        } 
        st = nxt[st][l];
      }
      g[i - 1][j] = min(g[i - 1][j], g[i][j] + A);
      g[i][j + 1] = min(g[i][j + 1], g[i][j] + A);
    }
  }
  cout << dp[1][n];
  return 0;
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         while (k + 1 < cands.size() && cands[k + 1] - u >= i) {
      |                ~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 34 ms 98908 KB Output is correct
2 Correct 32 ms 98900 KB Output is correct
3 Correct 41 ms 98872 KB Output is correct
4 Correct 33 ms 99008 KB Output is correct
5 Correct 32 ms 98936 KB Output is correct
6 Correct 33 ms 98900 KB Output is correct
7 Correct 32 ms 98896 KB Output is correct
8 Correct 34 ms 98896 KB Output is correct
9 Correct 34 ms 98908 KB Output is correct
10 Correct 32 ms 98908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 98908 KB Output is correct
2 Correct 31 ms 98928 KB Output is correct
3 Correct 162 ms 117584 KB Output is correct
4 Correct 199 ms 119632 KB Output is correct
5 Correct 237 ms 121560 KB Output is correct
6 Correct 260 ms 121684 KB Output is correct
7 Correct 307 ms 123312 KB Output is correct
8 Correct 336 ms 123220 KB Output is correct
9 Correct 335 ms 123196 KB Output is correct
10 Correct 35 ms 98900 KB Output is correct
11 Correct 33 ms 98908 KB Output is correct
12 Correct 33 ms 98904 KB Output is correct
13 Correct 32 ms 99052 KB Output is correct
14 Correct 31 ms 98896 KB Output is correct
15 Correct 37 ms 98900 KB Output is correct
16 Correct 34 ms 98868 KB Output is correct
17 Correct 41 ms 98892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 98908 KB Output is correct
2 Correct 32 ms 98900 KB Output is correct
3 Correct 41 ms 98872 KB Output is correct
4 Correct 33 ms 99008 KB Output is correct
5 Correct 32 ms 98936 KB Output is correct
6 Correct 33 ms 98900 KB Output is correct
7 Correct 32 ms 98896 KB Output is correct
8 Correct 34 ms 98896 KB Output is correct
9 Correct 34 ms 98908 KB Output is correct
10 Correct 32 ms 98908 KB Output is correct
11 Correct 34 ms 98920 KB Output is correct
12 Correct 33 ms 99000 KB Output is correct
13 Correct 33 ms 99064 KB Output is correct
14 Correct 33 ms 99032 KB Output is correct
15 Correct 33 ms 98900 KB Output is correct
16 Correct 40 ms 98900 KB Output is correct
17 Correct 33 ms 98900 KB Output is correct
18 Correct 32 ms 98900 KB Output is correct
19 Correct 33 ms 99068 KB Output is correct
20 Correct 32 ms 98900 KB Output is correct
21 Correct 32 ms 98900 KB Output is correct
22 Correct 33 ms 98896 KB Output is correct
23 Correct 32 ms 98908 KB Output is correct
24 Correct 33 ms 99084 KB Output is correct
25 Correct 35 ms 98904 KB Output is correct
26 Correct 33 ms 98908 KB Output is correct
27 Correct 32 ms 99068 KB Output is correct
28 Correct 32 ms 98896 KB Output is correct
29 Correct 34 ms 98900 KB Output is correct
30 Correct 34 ms 98896 KB Output is correct
31 Correct 33 ms 98904 KB Output is correct
32 Correct 34 ms 98924 KB Output is correct
33 Correct 33 ms 98972 KB Output is correct
34 Correct 33 ms 98896 KB Output is correct
35 Correct 35 ms 98900 KB Output is correct
36 Correct 33 ms 98904 KB Output is correct
37 Correct 34 ms 98908 KB Output is correct
38 Correct 32 ms 98900 KB Output is correct
39 Correct 32 ms 98900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 98908 KB Output is correct
2 Correct 32 ms 98900 KB Output is correct
3 Correct 41 ms 98872 KB Output is correct
4 Correct 33 ms 99008 KB Output is correct
5 Correct 32 ms 98936 KB Output is correct
6 Correct 33 ms 98900 KB Output is correct
7 Correct 32 ms 98896 KB Output is correct
8 Correct 34 ms 98896 KB Output is correct
9 Correct 34 ms 98908 KB Output is correct
10 Correct 32 ms 98908 KB Output is correct
11 Correct 34 ms 98920 KB Output is correct
12 Correct 33 ms 99000 KB Output is correct
13 Correct 33 ms 99064 KB Output is correct
14 Correct 33 ms 99032 KB Output is correct
15 Correct 33 ms 98900 KB Output is correct
16 Correct 40 ms 98900 KB Output is correct
17 Correct 33 ms 98900 KB Output is correct
18 Correct 32 ms 98900 KB Output is correct
19 Correct 33 ms 99068 KB Output is correct
20 Correct 32 ms 98900 KB Output is correct
21 Correct 32 ms 98900 KB Output is correct
22 Correct 33 ms 98896 KB Output is correct
23 Correct 32 ms 98908 KB Output is correct
24 Correct 33 ms 99084 KB Output is correct
25 Correct 35 ms 98904 KB Output is correct
26 Correct 33 ms 98908 KB Output is correct
27 Correct 32 ms 99068 KB Output is correct
28 Correct 32 ms 98896 KB Output is correct
29 Correct 34 ms 98900 KB Output is correct
30 Correct 34 ms 98896 KB Output is correct
31 Correct 33 ms 98904 KB Output is correct
32 Correct 34 ms 98924 KB Output is correct
33 Correct 33 ms 98972 KB Output is correct
34 Correct 33 ms 98896 KB Output is correct
35 Correct 35 ms 98900 KB Output is correct
36 Correct 33 ms 98904 KB Output is correct
37 Correct 34 ms 98908 KB Output is correct
38 Correct 32 ms 98900 KB Output is correct
39 Correct 32 ms 98900 KB Output is correct
40 Correct 34 ms 100944 KB Output is correct
41 Correct 41 ms 101004 KB Output is correct
42 Correct 40 ms 101004 KB Output is correct
43 Correct 35 ms 100956 KB Output is correct
44 Correct 36 ms 100948 KB Output is correct
45 Correct 35 ms 100952 KB Output is correct
46 Correct 34 ms 101012 KB Output is correct
47 Correct 34 ms 100948 KB Output is correct
48 Correct 36 ms 100948 KB Output is correct
49 Correct 35 ms 100956 KB Output is correct
50 Correct 35 ms 100948 KB Output is correct
51 Correct 34 ms 100956 KB Output is correct
52 Correct 35 ms 100948 KB Output is correct
53 Correct 35 ms 100968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 98908 KB Output is correct
2 Correct 32 ms 98900 KB Output is correct
3 Correct 41 ms 98872 KB Output is correct
4 Correct 33 ms 99008 KB Output is correct
5 Correct 32 ms 98936 KB Output is correct
6 Correct 33 ms 98900 KB Output is correct
7 Correct 32 ms 98896 KB Output is correct
8 Correct 34 ms 98896 KB Output is correct
9 Correct 34 ms 98908 KB Output is correct
10 Correct 32 ms 98908 KB Output is correct
11 Correct 34 ms 98920 KB Output is correct
12 Correct 33 ms 99000 KB Output is correct
13 Correct 33 ms 99064 KB Output is correct
14 Correct 33 ms 99032 KB Output is correct
15 Correct 33 ms 98900 KB Output is correct
16 Correct 40 ms 98900 KB Output is correct
17 Correct 33 ms 98900 KB Output is correct
18 Correct 32 ms 98900 KB Output is correct
19 Correct 33 ms 99068 KB Output is correct
20 Correct 32 ms 98900 KB Output is correct
21 Correct 32 ms 98900 KB Output is correct
22 Correct 33 ms 98896 KB Output is correct
23 Correct 32 ms 98908 KB Output is correct
24 Correct 33 ms 99084 KB Output is correct
25 Correct 35 ms 98904 KB Output is correct
26 Correct 33 ms 98908 KB Output is correct
27 Correct 32 ms 99068 KB Output is correct
28 Correct 32 ms 98896 KB Output is correct
29 Correct 34 ms 98900 KB Output is correct
30 Correct 34 ms 98896 KB Output is correct
31 Correct 33 ms 98904 KB Output is correct
32 Correct 34 ms 98924 KB Output is correct
33 Correct 33 ms 98972 KB Output is correct
34 Correct 33 ms 98896 KB Output is correct
35 Correct 35 ms 98900 KB Output is correct
36 Correct 33 ms 98904 KB Output is correct
37 Correct 34 ms 98908 KB Output is correct
38 Correct 32 ms 98900 KB Output is correct
39 Correct 32 ms 98900 KB Output is correct
40 Correct 34 ms 100944 KB Output is correct
41 Correct 41 ms 101004 KB Output is correct
42 Correct 40 ms 101004 KB Output is correct
43 Correct 35 ms 100956 KB Output is correct
44 Correct 36 ms 100948 KB Output is correct
45 Correct 35 ms 100952 KB Output is correct
46 Correct 34 ms 101012 KB Output is correct
47 Correct 34 ms 100948 KB Output is correct
48 Correct 36 ms 100948 KB Output is correct
49 Correct 35 ms 100956 KB Output is correct
50 Correct 35 ms 100948 KB Output is correct
51 Correct 34 ms 100956 KB Output is correct
52 Correct 35 ms 100948 KB Output is correct
53 Correct 35 ms 100968 KB Output is correct
54 Correct 40 ms 103108 KB Output is correct
55 Correct 79 ms 109396 KB Output is correct
56 Correct 71 ms 109360 KB Output is correct
57 Correct 74 ms 109396 KB Output is correct
58 Correct 69 ms 109244 KB Output is correct
59 Correct 71 ms 109392 KB Output is correct
60 Correct 71 ms 109396 KB Output is correct
61 Correct 69 ms 109396 KB Output is correct
62 Correct 71 ms 109392 KB Output is correct
63 Correct 71 ms 109364 KB Output is correct
64 Correct 74 ms 109396 KB Output is correct
65 Correct 75 ms 109392 KB Output is correct
66 Correct 77 ms 109396 KB Output is correct
67 Correct 68 ms 109392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 98908 KB Output is correct
2 Correct 32 ms 98900 KB Output is correct
3 Correct 41 ms 98872 KB Output is correct
4 Correct 33 ms 99008 KB Output is correct
5 Correct 32 ms 98936 KB Output is correct
6 Correct 33 ms 98900 KB Output is correct
7 Correct 32 ms 98896 KB Output is correct
8 Correct 34 ms 98896 KB Output is correct
9 Correct 34 ms 98908 KB Output is correct
10 Correct 32 ms 98908 KB Output is correct
11 Correct 32 ms 98908 KB Output is correct
12 Correct 31 ms 98928 KB Output is correct
13 Correct 162 ms 117584 KB Output is correct
14 Correct 199 ms 119632 KB Output is correct
15 Correct 237 ms 121560 KB Output is correct
16 Correct 260 ms 121684 KB Output is correct
17 Correct 307 ms 123312 KB Output is correct
18 Correct 336 ms 123220 KB Output is correct
19 Correct 335 ms 123196 KB Output is correct
20 Correct 35 ms 98900 KB Output is correct
21 Correct 33 ms 98908 KB Output is correct
22 Correct 33 ms 98904 KB Output is correct
23 Correct 32 ms 99052 KB Output is correct
24 Correct 31 ms 98896 KB Output is correct
25 Correct 37 ms 98900 KB Output is correct
26 Correct 34 ms 98868 KB Output is correct
27 Correct 41 ms 98892 KB Output is correct
28 Correct 34 ms 98920 KB Output is correct
29 Correct 33 ms 99000 KB Output is correct
30 Correct 33 ms 99064 KB Output is correct
31 Correct 33 ms 99032 KB Output is correct
32 Correct 33 ms 98900 KB Output is correct
33 Correct 40 ms 98900 KB Output is correct
34 Correct 33 ms 98900 KB Output is correct
35 Correct 32 ms 98900 KB Output is correct
36 Correct 33 ms 99068 KB Output is correct
37 Correct 32 ms 98900 KB Output is correct
38 Correct 32 ms 98900 KB Output is correct
39 Correct 33 ms 98896 KB Output is correct
40 Correct 32 ms 98908 KB Output is correct
41 Correct 33 ms 99084 KB Output is correct
42 Correct 35 ms 98904 KB Output is correct
43 Correct 33 ms 98908 KB Output is correct
44 Correct 32 ms 99068 KB Output is correct
45 Correct 32 ms 98896 KB Output is correct
46 Correct 34 ms 98900 KB Output is correct
47 Correct 34 ms 98896 KB Output is correct
48 Correct 33 ms 98904 KB Output is correct
49 Correct 34 ms 98924 KB Output is correct
50 Correct 33 ms 98972 KB Output is correct
51 Correct 33 ms 98896 KB Output is correct
52 Correct 35 ms 98900 KB Output is correct
53 Correct 33 ms 98904 KB Output is correct
54 Correct 34 ms 98908 KB Output is correct
55 Correct 32 ms 98900 KB Output is correct
56 Correct 32 ms 98900 KB Output is correct
57 Correct 34 ms 100944 KB Output is correct
58 Correct 41 ms 101004 KB Output is correct
59 Correct 40 ms 101004 KB Output is correct
60 Correct 35 ms 100956 KB Output is correct
61 Correct 36 ms 100948 KB Output is correct
62 Correct 35 ms 100952 KB Output is correct
63 Correct 34 ms 101012 KB Output is correct
64 Correct 34 ms 100948 KB Output is correct
65 Correct 36 ms 100948 KB Output is correct
66 Correct 35 ms 100956 KB Output is correct
67 Correct 35 ms 100948 KB Output is correct
68 Correct 34 ms 100956 KB Output is correct
69 Correct 35 ms 100948 KB Output is correct
70 Correct 35 ms 100968 KB Output is correct
71 Correct 40 ms 103108 KB Output is correct
72 Correct 79 ms 109396 KB Output is correct
73 Correct 71 ms 109360 KB Output is correct
74 Correct 74 ms 109396 KB Output is correct
75 Correct 69 ms 109244 KB Output is correct
76 Correct 71 ms 109392 KB Output is correct
77 Correct 71 ms 109396 KB Output is correct
78 Correct 69 ms 109396 KB Output is correct
79 Correct 71 ms 109392 KB Output is correct
80 Correct 71 ms 109364 KB Output is correct
81 Correct 74 ms 109396 KB Output is correct
82 Correct 75 ms 109392 KB Output is correct
83 Correct 77 ms 109396 KB Output is correct
84 Correct 68 ms 109392 KB Output is correct
85 Correct 126 ms 115352 KB Output is correct
86 Correct 270 ms 123268 KB Output is correct
87 Correct 249 ms 123220 KB Output is correct
88 Correct 252 ms 123220 KB Output is correct
89 Correct 316 ms 123216 KB Output is correct
90 Correct 243 ms 123216 KB Output is correct
91 Correct 261 ms 123260 KB Output is correct
92 Correct 278 ms 123216 KB Output is correct
93 Correct 245 ms 123220 KB Output is correct
94 Correct 255 ms 123220 KB Output is correct
95 Correct 353 ms 123020 KB Output is correct
96 Correct 334 ms 123240 KB Output is correct
97 Correct 244 ms 123156 KB Output is correct