Submission #945179

# Submission time Handle Problem Language Result Execution time Memory
945179 2024-03-13T13:39:23 Z vjudge1 Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
349 ms 49748 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#warning That's the baby, that's not my baby

typedef long long ll;

const int NMAX = 2500;
const int mod = 1e9 + 123;
const int P = 31;

int hsh[NMAX + 1], nxt[NMAX + 1];
std::vector<int> v[NMAX + 1];
ll dp[NMAX + 1][NMAX + 1];

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  std::cin >> n;

  std::string s;
  std::cin >> s;
  s = '#' + s;

  int A, B, C;
  std::cin >> A >> B >> C;

  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= n; j++) {
      dp[i][j] = 1e18;
    }
    for(int j = i; j <= n; j++) {
      dp[i][j] = (ll) (j - i + 1) * A;
    }
  }
  for(int len = 1; len <= n; len++) {
    std::vector<std::pair<int, int>> x;
    for(int i = 1; i <= n - len + 1; i++) {
      hsh[i] = ((ll) hsh[i] * 31 + (s[i + len - 1] - 'a' + 1)) % mod;
      dp[i][i + len - 1] = std::min({dp[i][i + len - 1], dp[i + 1][i + len - 1] + A, dp[i][i + len - 2] + A});
      x.push_back({hsh[i], i});
    }
    std::sort(x.begin(), x.end());
    int cur = 0;
    for(int i = 0; i < x.size(); i++) {
      if(!i || x[i].first != x[i - 1].first) {
        cur++;
      }
      v[cur].push_back(x[i].second);
    }
    for(int i = 1; i <= cur; i++) {
      for(int j = (int)v[i].size() - 1; j >= 0; j--) {
        int l = j + 1, r = v[i].size();
        while(l < r) {
          int mid = (l + r) / 2;
          if(v[i][mid] >= v[i][j] + len) {
            r = mid;
          } else {
            l = mid + 1;
          }
        }
        nxt[j] = r;
      }
      for(int j = 0; j < (int) v[i].size(); j++) {
        int cur = j, cnt = 0;
        while(cur < (int) v[i].size()) {
          int l = v[i][j], r = v[i][cur] + len - 1;
          dp[l][r] = std::min(dp[l][r], (ll)(cnt + 1) * C + (ll)(r - l + 1 - (cnt + 1) * len) * A + B + dp[l][l + len - 1]);
          cnt++;
          int x = nxt[cur];
          if(x == (int) v[i].size()) {
            break;
          }
          cur = x;
        }
      }
      v[i].clear();
    }
  }

  std::cout << dp[1][n];

  return 0;
}

Compilation message

copypaste3.cpp:6:2: warning: #warning That's the baby, that's not my baby [-Wcpp]
    6 | #warning That's the baby, that's not my baby
      |  ^~~~~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i = 0; i < x.size(); i++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 164 ms 37644 KB Output is correct
4 Correct 194 ms 39700 KB Output is correct
5 Correct 249 ms 43844 KB Output is correct
6 Correct 289 ms 45912 KB Output is correct
7 Correct 349 ms 49748 KB Output is correct
8 Correct 339 ms 49536 KB Output is correct
9 Correct 341 ms 49744 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 524 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2572 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 2 ms 2572 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 524 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2572 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 2 ms 2572 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 2 ms 4440 KB Output is correct
47 Correct 2 ms 4684 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4440 KB Output is correct
50 Correct 2 ms 4444 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4700 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 524 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2572 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 2 ms 2572 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 2 ms 4440 KB Output is correct
47 Correct 2 ms 4684 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4440 KB Output is correct
50 Correct 2 ms 4444 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4700 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
54 Correct 8 ms 10844 KB Output is correct
55 Correct 38 ms 21152 KB Output is correct
56 Correct 35 ms 21084 KB Output is correct
57 Correct 34 ms 21084 KB Output is correct
58 Correct 34 ms 21080 KB Output is correct
59 Correct 34 ms 21080 KB Output is correct
60 Correct 34 ms 21084 KB Output is correct
61 Correct 39 ms 21188 KB Output is correct
62 Correct 40 ms 21132 KB Output is correct
63 Correct 37 ms 21084 KB Output is correct
64 Correct 41 ms 21084 KB Output is correct
65 Correct 42 ms 21084 KB Output is correct
66 Correct 42 ms 21084 KB Output is correct
67 Correct 34 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 524 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 164 ms 37644 KB Output is correct
14 Correct 194 ms 39700 KB Output is correct
15 Correct 249 ms 43844 KB Output is correct
16 Correct 289 ms 45912 KB Output is correct
17 Correct 349 ms 49748 KB Output is correct
18 Correct 339 ms 49536 KB Output is correct
19 Correct 341 ms 49744 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 1 ms 2572 KB Output is correct
44 Correct 1 ms 2392 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2392 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 2 ms 2572 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 2 ms 4444 KB Output is correct
59 Correct 2 ms 4444 KB Output is correct
60 Correct 2 ms 4444 KB Output is correct
61 Correct 2 ms 4444 KB Output is correct
62 Correct 2 ms 4444 KB Output is correct
63 Correct 2 ms 4440 KB Output is correct
64 Correct 2 ms 4684 KB Output is correct
65 Correct 2 ms 4444 KB Output is correct
66 Correct 2 ms 4440 KB Output is correct
67 Correct 2 ms 4444 KB Output is correct
68 Correct 2 ms 4444 KB Output is correct
69 Correct 2 ms 4700 KB Output is correct
70 Correct 2 ms 4444 KB Output is correct
71 Correct 8 ms 10844 KB Output is correct
72 Correct 38 ms 21152 KB Output is correct
73 Correct 35 ms 21084 KB Output is correct
74 Correct 34 ms 21084 KB Output is correct
75 Correct 34 ms 21080 KB Output is correct
76 Correct 34 ms 21080 KB Output is correct
77 Correct 34 ms 21084 KB Output is correct
78 Correct 39 ms 21188 KB Output is correct
79 Correct 40 ms 21132 KB Output is correct
80 Correct 37 ms 21084 KB Output is correct
81 Correct 41 ms 21084 KB Output is correct
82 Correct 42 ms 21084 KB Output is correct
83 Correct 42 ms 21084 KB Output is correct
84 Correct 34 ms 21084 KB Output is correct
85 Correct 92 ms 33596 KB Output is correct
86 Correct 237 ms 49564 KB Output is correct
87 Correct 232 ms 49496 KB Output is correct
88 Correct 229 ms 49636 KB Output is correct
89 Incorrect 223 ms 49624 KB Output isn't correct
90 Halted 0 ms 0 KB -