답안 #945187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945187 2024-03-13T13:43:22 Z vjudge1 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
368 ms 50000 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 + 2;
const int mod = 1e9 + 7;
const int P = 37;

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] * P + (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++) {
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 500 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 150 ms 37468 KB Output is correct
4 Correct 185 ms 39768 KB Output is correct
5 Correct 248 ms 44116 KB Output is correct
6 Correct 283 ms 45980 KB Output is correct
7 Correct 335 ms 49660 KB Output is correct
8 Correct 347 ms 49500 KB Output is correct
9 Correct 344 ms 49680 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 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 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 500 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 600 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 0 ms 348 KB Output is correct
19 Correct 0 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 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 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 0 ms 2396 KB Output is correct
33 Correct 1 ms 2480 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 612 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 500 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 600 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 0 ms 348 KB Output is correct
19 Correct 0 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 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 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 0 ms 2396 KB Output is correct
33 Correct 1 ms 2480 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 612 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2644 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 4440 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 4444 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 4444 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 500 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 600 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 0 ms 348 KB Output is correct
19 Correct 0 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 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 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 0 ms 2396 KB Output is correct
33 Correct 1 ms 2480 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 612 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2644 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 4440 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 4444 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 4444 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 10844 KB Output is correct
55 Correct 32 ms 21084 KB Output is correct
56 Correct 34 ms 21084 KB Output is correct
57 Correct 33 ms 21084 KB Output is correct
58 Correct 31 ms 21080 KB Output is correct
59 Correct 32 ms 21084 KB Output is correct
60 Correct 31 ms 21084 KB Output is correct
61 Correct 39 ms 21204 KB Output is correct
62 Correct 38 ms 21084 KB Output is correct
63 Correct 36 ms 21084 KB Output is correct
64 Correct 36 ms 21080 KB Output is correct
65 Correct 41 ms 21084 KB Output is correct
66 Correct 41 ms 21084 KB Output is correct
67 Correct 32 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 500 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 150 ms 37468 KB Output is correct
14 Correct 185 ms 39768 KB Output is correct
15 Correct 248 ms 44116 KB Output is correct
16 Correct 283 ms 45980 KB Output is correct
17 Correct 335 ms 49660 KB Output is correct
18 Correct 347 ms 49500 KB Output is correct
19 Correct 344 ms 49680 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 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 0 ms 348 KB Output is correct
25 Correct 0 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 0 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 600 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 0 ms 348 KB Output is correct
36 Correct 0 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 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 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 0 ms 2396 KB Output is correct
50 Correct 1 ms 2480 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 612 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 2644 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 4440 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 4444 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 4444 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 10844 KB Output is correct
72 Correct 32 ms 21084 KB Output is correct
73 Correct 34 ms 21084 KB Output is correct
74 Correct 33 ms 21084 KB Output is correct
75 Correct 31 ms 21080 KB Output is correct
76 Correct 32 ms 21084 KB Output is correct
77 Correct 31 ms 21084 KB Output is correct
78 Correct 39 ms 21204 KB Output is correct
79 Correct 38 ms 21084 KB Output is correct
80 Correct 36 ms 21084 KB Output is correct
81 Correct 36 ms 21080 KB Output is correct
82 Correct 41 ms 21084 KB Output is correct
83 Correct 41 ms 21084 KB Output is correct
84 Correct 32 ms 21084 KB Output is correct
85 Correct 91 ms 33680 KB Output is correct
86 Correct 221 ms 49756 KB Output is correct
87 Correct 214 ms 49816 KB Output is correct
88 Correct 215 ms 49752 KB Output is correct
89 Correct 206 ms 49752 KB Output is correct
90 Correct 208 ms 49756 KB Output is correct
91 Correct 333 ms 49668 KB Output is correct
92 Correct 368 ms 49500 KB Output is correct
93 Correct 246 ms 50000 KB Output is correct
94 Correct 252 ms 49748 KB Output is correct
95 Correct 337 ms 49964 KB Output is correct
96 Correct 332 ms 49748 KB Output is correct
97 Correct 208 ms 49752 KB Output is correct