답안 #998176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998176 2024-06-13T11:30:00 Z abczz Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
231 ms 131928 KB
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#define ll long long

using namespace std;

string S;
const ll M = 1e9 + 9;
unordered_map <ll, ll> mp;
ll n, a, b, c, s, base = 37, 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';
}
# 결과 실행 시간 메모리 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 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 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 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 92 ms 96772 KB Output is correct
4 Correct 111 ms 103760 KB Output is correct
5 Correct 132 ms 112984 KB Output is correct
6 Correct 173 ms 122416 KB Output is correct
7 Correct 224 ms 131412 KB Output is correct
8 Correct 217 ms 131924 KB Output is correct
9 Correct 231 ms 131832 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 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
# 결과 실행 시간 메모리 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 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 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 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 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 2392 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 4696 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 0 ms 4700 KB Output is correct
27 Correct 0 ms 4700 KB Output is correct
28 Correct 0 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 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 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
# 결과 실행 시간 메모리 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 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 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 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 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 2392 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 4696 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 0 ms 4700 KB Output is correct
27 Correct 0 ms 4700 KB Output is correct
28 Correct 0 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 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 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 7008 KB Output is correct
41 Correct 2 ms 11624 KB Output is correct
42 Correct 2 ms 11624 KB Output is correct
43 Correct 2 ms 11736 KB Output is correct
44 Correct 2 ms 11624 KB Output is correct
45 Correct 2 ms 11616 KB Output is correct
46 Correct 2 ms 11612 KB Output is correct
47 Correct 2 ms 11612 KB Output is correct
48 Correct 2 ms 11568 KB Output is correct
49 Correct 2 ms 11612 KB Output is correct
50 Correct 2 ms 11612 KB Output is correct
51 Correct 3 ms 11612 KB Output is correct
52 Correct 2 ms 11612 KB Output is correct
53 Correct 2 ms 11612 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 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 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 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 2392 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 4696 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 0 ms 4700 KB Output is correct
27 Correct 0 ms 4700 KB Output is correct
28 Correct 0 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 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 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 7008 KB Output is correct
41 Correct 2 ms 11624 KB Output is correct
42 Correct 2 ms 11624 KB Output is correct
43 Correct 2 ms 11736 KB Output is correct
44 Correct 2 ms 11624 KB Output is correct
45 Correct 2 ms 11616 KB Output is correct
46 Correct 2 ms 11612 KB Output is correct
47 Correct 2 ms 11612 KB Output is correct
48 Correct 2 ms 11568 KB Output is correct
49 Correct 2 ms 11612 KB Output is correct
50 Correct 2 ms 11612 KB Output is correct
51 Correct 3 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 23644 KB Output is correct
55 Correct 29 ms 51540 KB Output is correct
56 Correct 27 ms 51540 KB Output is correct
57 Correct 24 ms 51544 KB Output is correct
58 Correct 24 ms 51548 KB Output is correct
59 Correct 22 ms 51544 KB Output is correct
60 Correct 24 ms 51384 KB Output is correct
61 Correct 23 ms 51536 KB Output is correct
62 Correct 24 ms 51548 KB Output is correct
63 Correct 23 ms 51500 KB Output is correct
64 Correct 25 ms 51536 KB Output is correct
65 Correct 28 ms 51544 KB Output is correct
66 Correct 28 ms 51548 KB Output is correct
67 Correct 23 ms 51456 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 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 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 92 ms 96772 KB Output is correct
14 Correct 111 ms 103760 KB Output is correct
15 Correct 132 ms 112984 KB Output is correct
16 Correct 173 ms 122416 KB Output is correct
17 Correct 224 ms 131412 KB Output is correct
18 Correct 217 ms 131924 KB Output is correct
19 Correct 231 ms 131832 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 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 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 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 2392 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4696 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 0 ms 4700 KB Output is correct
44 Correct 0 ms 4700 KB Output is correct
45 Correct 0 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 4700 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 0 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 0 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 7008 KB Output is correct
58 Correct 2 ms 11624 KB Output is correct
59 Correct 2 ms 11624 KB Output is correct
60 Correct 2 ms 11736 KB Output is correct
61 Correct 2 ms 11624 KB Output is correct
62 Correct 2 ms 11616 KB Output is correct
63 Correct 2 ms 11612 KB Output is correct
64 Correct 2 ms 11612 KB Output is correct
65 Correct 2 ms 11568 KB Output is correct
66 Correct 2 ms 11612 KB Output is correct
67 Correct 2 ms 11612 KB Output is correct
68 Correct 3 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 23644 KB Output is correct
72 Correct 29 ms 51540 KB Output is correct
73 Correct 27 ms 51540 KB Output is correct
74 Correct 24 ms 51544 KB Output is correct
75 Correct 24 ms 51548 KB Output is correct
76 Correct 22 ms 51544 KB Output is correct
77 Correct 24 ms 51384 KB Output is correct
78 Correct 23 ms 51536 KB Output is correct
79 Correct 24 ms 51548 KB Output is correct
80 Correct 23 ms 51500 KB Output is correct
81 Correct 25 ms 51536 KB Output is correct
82 Correct 28 ms 51544 KB Output is correct
83 Correct 28 ms 51548 KB Output is correct
84 Correct 23 ms 51456 KB Output is correct
85 Correct 59 ms 80212 KB Output is correct
86 Correct 137 ms 131928 KB Output is correct
87 Correct 146 ms 131924 KB Output is correct
88 Correct 122 ms 131920 KB Output is correct
89 Incorrect 121 ms 131920 KB Output isn't correct
90 Halted 0 ms 0 KB -