답안 #945180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945180 2024-03-13T13:39:58 Z vjudge1 Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
377 ms 49820 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 + 123;
const int P = 31;

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++) {
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 147 ms 37700 KB Output is correct
4 Correct 197 ms 39756 KB Output is correct
5 Correct 241 ms 43864 KB Output is correct
6 Correct 317 ms 46168 KB Output is correct
7 Correct 333 ms 49624 KB Output is correct
8 Correct 377 ms 49620 KB Output is correct
9 Correct 339 ms 49620 KB Output is correct
10 Correct 0 ms 600 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 344 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 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 344 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 2392 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 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 2392 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 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 344 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 2392 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 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 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 2 ms 4444 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4700 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 4440 KB Output is correct
48 Correct 2 ms 4440 KB Output is correct
49 Correct 2 ms 4696 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 1 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 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 344 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 2392 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 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 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 2 ms 4444 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4700 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 4440 KB Output is correct
48 Correct 2 ms 4440 KB Output is correct
49 Correct 2 ms 4696 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 10840 KB Output is correct
55 Correct 32 ms 21084 KB Output is correct
56 Correct 33 ms 21084 KB Output is correct
57 Correct 32 ms 21080 KB Output is correct
58 Correct 31 ms 21080 KB Output is correct
59 Correct 31 ms 21084 KB Output is correct
60 Correct 36 ms 21336 KB Output is correct
61 Correct 38 ms 21188 KB Output is correct
62 Correct 38 ms 21084 KB Output is correct
63 Correct 36 ms 21092 KB Output is correct
64 Correct 36 ms 21088 KB Output is correct
65 Correct 41 ms 21084 KB Output is correct
66 Correct 40 ms 21084 KB Output is correct
67 Correct 33 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 147 ms 37700 KB Output is correct
14 Correct 197 ms 39756 KB Output is correct
15 Correct 241 ms 43864 KB Output is correct
16 Correct 317 ms 46168 KB Output is correct
17 Correct 333 ms 49624 KB Output is correct
18 Correct 377 ms 49620 KB Output is correct
19 Correct 339 ms 49620 KB Output is correct
20 Correct 0 ms 600 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 344 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 348 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 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 344 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 2392 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 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 2392 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 4700 KB Output is correct
60 Correct 2 ms 4444 KB Output is correct
61 Correct 2 ms 4700 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 4440 KB Output is correct
65 Correct 2 ms 4440 KB Output is correct
66 Correct 2 ms 4696 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 10840 KB Output is correct
72 Correct 32 ms 21084 KB Output is correct
73 Correct 33 ms 21084 KB Output is correct
74 Correct 32 ms 21080 KB Output is correct
75 Correct 31 ms 21080 KB Output is correct
76 Correct 31 ms 21084 KB Output is correct
77 Correct 36 ms 21336 KB Output is correct
78 Correct 38 ms 21188 KB Output is correct
79 Correct 38 ms 21084 KB Output is correct
80 Correct 36 ms 21092 KB Output is correct
81 Correct 36 ms 21088 KB Output is correct
82 Correct 41 ms 21084 KB Output is correct
83 Correct 40 ms 21084 KB Output is correct
84 Correct 33 ms 21084 KB Output is correct
85 Correct 81 ms 33624 KB Output is correct
86 Correct 222 ms 49820 KB Output is correct
87 Correct 213 ms 49788 KB Output is correct
88 Correct 212 ms 49500 KB Output is correct
89 Incorrect 214 ms 49708 KB Output isn't correct
90 Halted 0 ms 0 KB -