답안 #998234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998234 2024-06-13T12:16:19 Z abczz Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
213 ms 132104 KB
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#define ll long long
#define int 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];
signed 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 2396 KB Output is correct
2 Correct 0 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 1 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 0 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 0 ms 2396 KB Output is correct
3 Correct 88 ms 96848 KB Output is correct
4 Correct 107 ms 103760 KB Output is correct
5 Correct 170 ms 113132 KB Output is correct
6 Correct 159 ms 122708 KB Output is correct
7 Correct 191 ms 131920 KB Output is correct
8 Correct 213 ms 131840 KB Output is correct
9 Correct 197 ms 131920 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 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 1 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 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4556 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 2396 KB Output is correct
18 Correct 0 ms 2396 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 4556 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 4696 KB Output is correct
27 Correct 2 ms 4700 KB Output is correct
28 Correct 1 ms 4556 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 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 0 ms 2396 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 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 1 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 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4556 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 2396 KB Output is correct
18 Correct 0 ms 2396 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 4556 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 4696 KB Output is correct
27 Correct 2 ms 4700 KB Output is correct
28 Correct 1 ms 4556 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 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 0 ms 2396 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4564 KB Output is correct
40 Correct 2 ms 7000 KB Output is correct
41 Correct 3 ms 11612 KB Output is correct
42 Correct 3 ms 11612 KB Output is correct
43 Correct 3 ms 11612 KB Output is correct
44 Correct 3 ms 11612 KB Output is correct
45 Correct 3 ms 11612 KB Output is correct
46 Correct 2 ms 11612 KB Output is correct
47 Correct 3 ms 11612 KB Output is correct
48 Correct 3 ms 11612 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 11608 KB Output is correct
53 Correct 2 ms 11744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 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 1 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 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4556 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 2396 KB Output is correct
18 Correct 0 ms 2396 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 4556 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 4696 KB Output is correct
27 Correct 2 ms 4700 KB Output is correct
28 Correct 1 ms 4556 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 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 0 ms 2396 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4564 KB Output is correct
40 Correct 2 ms 7000 KB Output is correct
41 Correct 3 ms 11612 KB Output is correct
42 Correct 3 ms 11612 KB Output is correct
43 Correct 3 ms 11612 KB Output is correct
44 Correct 3 ms 11612 KB Output is correct
45 Correct 3 ms 11612 KB Output is correct
46 Correct 2 ms 11612 KB Output is correct
47 Correct 3 ms 11612 KB Output is correct
48 Correct 3 ms 11612 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 11608 KB Output is correct
53 Correct 2 ms 11744 KB Output is correct
54 Correct 6 ms 23500 KB Output is correct
55 Correct 25 ms 51488 KB Output is correct
56 Correct 27 ms 51556 KB Output is correct
57 Correct 25 ms 51484 KB Output is correct
58 Correct 24 ms 51596 KB Output is correct
59 Correct 25 ms 51548 KB Output is correct
60 Correct 23 ms 51468 KB Output is correct
61 Correct 22 ms 51548 KB Output is correct
62 Correct 33 ms 51540 KB Output is correct
63 Correct 26 ms 51556 KB Output is correct
64 Correct 24 ms 51548 KB Output is correct
65 Correct 27 ms 51536 KB Output is correct
66 Correct 26 ms 51820 KB Output is correct
67 Correct 29 ms 51512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 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 1 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 0 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 0 ms 2396 KB Output is correct
13 Correct 88 ms 96848 KB Output is correct
14 Correct 107 ms 103760 KB Output is correct
15 Correct 170 ms 113132 KB Output is correct
16 Correct 159 ms 122708 KB Output is correct
17 Correct 191 ms 131920 KB Output is correct
18 Correct 213 ms 131840 KB Output is correct
19 Correct 197 ms 131920 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 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 4440 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 4556 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 2396 KB Output is correct
35 Correct 0 ms 2396 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 4556 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 4696 KB Output is correct
44 Correct 2 ms 4700 KB Output is correct
45 Correct 1 ms 4556 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 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 0 ms 2396 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 4564 KB Output is correct
57 Correct 2 ms 7000 KB Output is correct
58 Correct 3 ms 11612 KB Output is correct
59 Correct 3 ms 11612 KB Output is correct
60 Correct 3 ms 11612 KB Output is correct
61 Correct 3 ms 11612 KB Output is correct
62 Correct 3 ms 11612 KB Output is correct
63 Correct 2 ms 11612 KB Output is correct
64 Correct 3 ms 11612 KB Output is correct
65 Correct 3 ms 11612 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 11608 KB Output is correct
70 Correct 2 ms 11744 KB Output is correct
71 Correct 6 ms 23500 KB Output is correct
72 Correct 25 ms 51488 KB Output is correct
73 Correct 27 ms 51556 KB Output is correct
74 Correct 25 ms 51484 KB Output is correct
75 Correct 24 ms 51596 KB Output is correct
76 Correct 25 ms 51548 KB Output is correct
77 Correct 23 ms 51468 KB Output is correct
78 Correct 22 ms 51548 KB Output is correct
79 Correct 33 ms 51540 KB Output is correct
80 Correct 26 ms 51556 KB Output is correct
81 Correct 24 ms 51548 KB Output is correct
82 Correct 27 ms 51536 KB Output is correct
83 Correct 26 ms 51820 KB Output is correct
84 Correct 29 ms 51512 KB Output is correct
85 Correct 60 ms 80332 KB Output is correct
86 Correct 161 ms 132104 KB Output is correct
87 Correct 137 ms 131924 KB Output is correct
88 Correct 129 ms 131920 KB Output is correct
89 Incorrect 162 ms 131868 KB Output isn't correct
90 Halted 0 ms 0 KB -