Submission #998174

# Submission time Handle Problem Language Result Execution time Memory
998174 2024-06-13T11:29:00 Z abczz Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
217 ms 132000 KB
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#define ll long long

using namespace std;

string S;
const ll M = 1e9 + 7;
unordered_map <ll, ll> mp;
ll n, a, b, c, s, base = 30, p, X[2500][2500], dp[2500][2500], nx[2500][2500];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> n >> S >> a >> b >> c;
  for (int i=0; i<n; ++i) {
    s = 0, p = 1;
    for (int j=i; j<n; ++j) {
      (s += (S[j]-'a'+1) * p % M) %= M;
      (p *= base) %= M;
      X[i][j] = s;
    }
  }
  for (int len=0; len<n; ++len) {
    mp.clear();
    for (int i=n-len-1; i>=0; --i) {
      if (i+2*len+1 < n) {
        mp[X[i+len+1][i+2*len+1]] = i+len+1;
      }
      if (mp.count(X[i][i+len])) nx[i][i+len] = mp[X[i][i+len]];
      else nx[i][i+len] = -1;
    }
    for (int i=0; i+len<n; ++i) {
      if (len) {
        dp[i][i+len] = min(dp[i][i+len], min(dp[i][i+len-1], dp[i+1][i+len]));
      }
      s = 0;
      int j = i;
      while (true) {
        int k = nx[j][j+len];
        ++s;
        if (k == -1) break;
        dp[i][k+len] = min(dp[i][k+len], dp[i][i+len] + b + (s+1) * c - (s * (len+1) * a));
        j = k;
      }
    }
  }
  cout << a*n + dp[0][n-1] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 95 ms 96756 KB Output is correct
4 Correct 108 ms 103676 KB Output is correct
5 Correct 129 ms 113056 KB Output is correct
6 Correct 163 ms 122560 KB Output is correct
7 Correct 217 ms 131804 KB Output is correct
8 Correct 196 ms 131924 KB Output is correct
9 Correct 206 ms 131924 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 0 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 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4696 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4696 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 6860 KB Output is correct
41 Correct 2 ms 11612 KB Output is correct
42 Correct 2 ms 11612 KB Output is correct
43 Correct 2 ms 11612 KB Output is correct
44 Correct 2 ms 11612 KB Output is correct
45 Correct 2 ms 11612 KB Output is correct
46 Correct 3 ms 11492 KB Output is correct
47 Correct 2 ms 11612 KB Output is correct
48 Correct 2 ms 11864 KB Output is correct
49 Correct 2 ms 11612 KB Output is correct
50 Correct 2 ms 11612 KB Output is correct
51 Correct 2 ms 11612 KB Output is correct
52 Correct 2 ms 11612 KB Output is correct
53 Correct 2 ms 11612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4696 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 6860 KB Output is correct
41 Correct 2 ms 11612 KB Output is correct
42 Correct 2 ms 11612 KB Output is correct
43 Correct 2 ms 11612 KB Output is correct
44 Correct 2 ms 11612 KB Output is correct
45 Correct 2 ms 11612 KB Output is correct
46 Correct 3 ms 11492 KB Output is correct
47 Correct 2 ms 11612 KB Output is correct
48 Correct 2 ms 11864 KB Output is correct
49 Correct 2 ms 11612 KB Output is correct
50 Correct 2 ms 11612 KB Output is correct
51 Correct 2 ms 11612 KB Output is correct
52 Correct 2 ms 11612 KB Output is correct
53 Correct 2 ms 11612 KB Output is correct
54 Correct 7 ms 23896 KB Output is correct
55 Correct 29 ms 51536 KB Output is correct
56 Correct 27 ms 51548 KB Output is correct
57 Correct 26 ms 51556 KB Output is correct
58 Correct 24 ms 51548 KB Output is correct
59 Correct 26 ms 51540 KB Output is correct
60 Correct 25 ms 51548 KB Output is correct
61 Correct 23 ms 51548 KB Output is correct
62 Correct 30 ms 51512 KB Output is correct
63 Correct 28 ms 51448 KB Output is correct
64 Correct 23 ms 51536 KB Output is correct
65 Correct 27 ms 51544 KB Output is correct
66 Correct 26 ms 51548 KB Output is correct
67 Correct 22 ms 51548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 95 ms 96756 KB Output is correct
14 Correct 108 ms 103676 KB Output is correct
15 Correct 129 ms 113056 KB Output is correct
16 Correct 163 ms 122560 KB Output is correct
17 Correct 217 ms 131804 KB Output is correct
18 Correct 196 ms 131924 KB Output is correct
19 Correct 206 ms 131924 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 0 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4700 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4700 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 1 ms 4696 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4700 KB Output is correct
57 Correct 1 ms 6860 KB Output is correct
58 Correct 2 ms 11612 KB Output is correct
59 Correct 2 ms 11612 KB Output is correct
60 Correct 2 ms 11612 KB Output is correct
61 Correct 2 ms 11612 KB Output is correct
62 Correct 2 ms 11612 KB Output is correct
63 Correct 3 ms 11492 KB Output is correct
64 Correct 2 ms 11612 KB Output is correct
65 Correct 2 ms 11864 KB Output is correct
66 Correct 2 ms 11612 KB Output is correct
67 Correct 2 ms 11612 KB Output is correct
68 Correct 2 ms 11612 KB Output is correct
69 Correct 2 ms 11612 KB Output is correct
70 Correct 2 ms 11612 KB Output is correct
71 Correct 7 ms 23896 KB Output is correct
72 Correct 29 ms 51536 KB Output is correct
73 Correct 27 ms 51548 KB Output is correct
74 Correct 26 ms 51556 KB Output is correct
75 Correct 24 ms 51548 KB Output is correct
76 Correct 26 ms 51540 KB Output is correct
77 Correct 25 ms 51548 KB Output is correct
78 Correct 23 ms 51548 KB Output is correct
79 Correct 30 ms 51512 KB Output is correct
80 Correct 28 ms 51448 KB Output is correct
81 Correct 23 ms 51536 KB Output is correct
82 Correct 27 ms 51544 KB Output is correct
83 Correct 26 ms 51548 KB Output is correct
84 Correct 22 ms 51548 KB Output is correct
85 Correct 63 ms 80304 KB Output is correct
86 Correct 158 ms 132000 KB Output is correct
87 Correct 132 ms 131924 KB Output is correct
88 Correct 129 ms 131924 KB Output is correct
89 Incorrect 127 ms 131924 KB Output isn't correct
90 Halted 0 ms 0 KB -