Submission #945183

# Submission time Handle Problem Language Result Execution time Memory
945183 2024-03-13T13:41:12 Z vjudge1 Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
355 ms 49828 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#define int long long
#warning That's the baby, that's not my baby

typedef long long ll;

const int NMAX = 2500;
const int mod = 1e9 + 7;
const int P = 41;

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

signed 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:7:2: warning: #warning That's the baby, that's not my baby [-Wcpp]
    7 | #warning That's the baby, that's not my baby
      |  ^~~~~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:50:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i = 0; i < x.size(); i++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 167 ms 37716 KB Output is correct
4 Correct 199 ms 39772 KB Output is correct
5 Correct 235 ms 43864 KB Output is correct
6 Correct 298 ms 45972 KB Output is correct
7 Correct 350 ms 49620 KB Output is correct
8 Correct 352 ms 49616 KB Output is correct
9 Correct 355 ms 49616 KB Output is correct
10 Correct 1 ms 544 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 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 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 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 2396 KB Output is correct
22 Correct 1 ms 2408 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 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 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 2396 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 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 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 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 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 2396 KB Output is correct
22 Correct 1 ms 2408 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 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 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 2396 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 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2392 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 4700 KB Output is correct
43 Correct 2 ms 4700 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4440 KB Output is correct
46 Correct 2 ms 4440 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4440 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 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 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 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 2396 KB Output is correct
22 Correct 1 ms 2408 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 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 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 2396 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 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2392 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 4700 KB Output is correct
43 Correct 2 ms 4700 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4440 KB Output is correct
46 Correct 2 ms 4440 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4440 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
54 Correct 7 ms 10840 KB Output is correct
55 Correct 31 ms 21084 KB Output is correct
56 Correct 32 ms 21084 KB Output is correct
57 Correct 31 ms 21252 KB Output is correct
58 Correct 36 ms 21332 KB Output is correct
59 Correct 31 ms 21084 KB Output is correct
60 Correct 31 ms 21084 KB Output is correct
61 Correct 37 ms 21084 KB Output is correct
62 Correct 39 ms 21080 KB Output is correct
63 Correct 36 ms 21084 KB Output is correct
64 Correct 36 ms 21084 KB Output is correct
65 Correct 40 ms 21224 KB Output is correct
66 Correct 46 ms 21228 KB Output is correct
67 Correct 31 ms 21080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 167 ms 37716 KB Output is correct
14 Correct 199 ms 39772 KB Output is correct
15 Correct 235 ms 43864 KB Output is correct
16 Correct 298 ms 45972 KB Output is correct
17 Correct 350 ms 49620 KB Output is correct
18 Correct 352 ms 49616 KB Output is correct
19 Correct 355 ms 49616 KB Output is correct
20 Correct 1 ms 544 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 348 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 2392 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 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 2396 KB Output is correct
39 Correct 1 ms 2408 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 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 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 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2392 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 4700 KB Output is correct
60 Correct 2 ms 4700 KB Output is correct
61 Correct 2 ms 4444 KB Output is correct
62 Correct 2 ms 4440 KB Output is correct
63 Correct 2 ms 4440 KB Output is correct
64 Correct 2 ms 4444 KB Output is correct
65 Correct 2 ms 4444 KB Output is correct
66 Correct 2 ms 4444 KB Output is correct
67 Correct 2 ms 4440 KB Output is correct
68 Correct 2 ms 4444 KB Output is correct
69 Correct 2 ms 4444 KB Output is correct
70 Correct 2 ms 4444 KB Output is correct
71 Correct 7 ms 10840 KB Output is correct
72 Correct 31 ms 21084 KB Output is correct
73 Correct 32 ms 21084 KB Output is correct
74 Correct 31 ms 21252 KB Output is correct
75 Correct 36 ms 21332 KB Output is correct
76 Correct 31 ms 21084 KB Output is correct
77 Correct 31 ms 21084 KB Output is correct
78 Correct 37 ms 21084 KB Output is correct
79 Correct 39 ms 21080 KB Output is correct
80 Correct 36 ms 21084 KB Output is correct
81 Correct 36 ms 21084 KB Output is correct
82 Correct 40 ms 21224 KB Output is correct
83 Correct 46 ms 21228 KB Output is correct
84 Correct 31 ms 21080 KB Output is correct
85 Correct 95 ms 33672 KB Output is correct
86 Correct 243 ms 49828 KB Output is correct
87 Correct 211 ms 49776 KB Output is correct
88 Correct 210 ms 49756 KB Output is correct
89 Correct 215 ms 49496 KB Output is correct
90 Incorrect 212 ms 49500 KB Output isn't correct
91 Halted 0 ms 0 KB -