답안 #998242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998242 2024-06-13T12:25:07 Z abczz Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
437 ms 181348 KB
#include <iostream>
#include <vector>
#include <array>
#include <map>
#define ll long long

using namespace std;

string S;
const ll M = 1e9 + 7, M2 = 1e9 + 11;
map <array<ll, 2>, ll> mp;
array <ll, 2> X[2510][2510];
ll n, a, b, c, s, s2, base = 37, base2 = 41, p, p2, dp[2510][2500], nx[2510][2510];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> n >> S >> a >> b >> c;
  for (ll i=0; i<n; ++i) {
    s = s2 = 0, p = p2 = 1;
    for (ll j=i; j<n; ++j) {
      (s += (S[j]-'a'+1) * p % M) %= M;
      (p *= base) %= M;
      (s2 += (S[j]-'a'+1) * p2 % M) %= M;
      (p2 *= base) %= M;
      X[i][j] = {s, s2};
    }
  }
  for (ll len=0; len<n; ++len) {
    mp.clear();
    for (ll 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 (ll 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;
      ll j = i;
      while (true) {
        ll 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 2392 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 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 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 6492 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 129 ms 128704 KB Output is correct
4 Correct 134 ms 138236 KB Output is correct
5 Correct 174 ms 146768 KB Output is correct
6 Correct 245 ms 157812 KB Output is correct
7 Correct 278 ms 165612 KB Output is correct
8 Correct 273 ms 163920 KB Output is correct
9 Correct 273 ms 165460 KB Output is correct
10 Correct 1 ms 2392 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 4444 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6748 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 2392 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 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6744 KB Output is correct
30 Correct 1 ms 6744 KB Output is correct
31 Correct 1 ms 6744 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 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 2396 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 6576 KB Output is correct
39 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 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 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6744 KB Output is correct
30 Correct 1 ms 6744 KB Output is correct
31 Correct 1 ms 6744 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 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 2396 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 6576 KB Output is correct
39 Correct 1 ms 6748 KB Output is correct
40 Correct 2 ms 9052 KB Output is correct
41 Correct 3 ms 15824 KB Output is correct
42 Correct 4 ms 15708 KB Output is correct
43 Correct 4 ms 15704 KB Output is correct
44 Correct 4 ms 15708 KB Output is correct
45 Correct 4 ms 15708 KB Output is correct
46 Correct 3 ms 15708 KB Output is correct
47 Correct 3 ms 15704 KB Output is correct
48 Correct 4 ms 15840 KB Output is correct
49 Correct 3 ms 15708 KB Output is correct
50 Correct 3 ms 15708 KB Output is correct
51 Correct 3 ms 15708 KB Output is correct
52 Correct 3 ms 15824 KB Output is correct
53 Correct 3 ms 15708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 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 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6744 KB Output is correct
30 Correct 1 ms 6744 KB Output is correct
31 Correct 1 ms 6744 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 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 2396 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 6576 KB Output is correct
39 Correct 1 ms 6748 KB Output is correct
40 Correct 2 ms 9052 KB Output is correct
41 Correct 3 ms 15824 KB Output is correct
42 Correct 4 ms 15708 KB Output is correct
43 Correct 4 ms 15704 KB Output is correct
44 Correct 4 ms 15708 KB Output is correct
45 Correct 4 ms 15708 KB Output is correct
46 Correct 3 ms 15708 KB Output is correct
47 Correct 3 ms 15704 KB Output is correct
48 Correct 4 ms 15840 KB Output is correct
49 Correct 3 ms 15708 KB Output is correct
50 Correct 3 ms 15708 KB Output is correct
51 Correct 3 ms 15708 KB Output is correct
52 Correct 3 ms 15824 KB Output is correct
53 Correct 3 ms 15708 KB Output is correct
54 Correct 16 ms 33912 KB Output is correct
55 Correct 37 ms 72028 KB Output is correct
56 Correct 59 ms 72028 KB Output is correct
57 Correct 68 ms 72080 KB Output is correct
58 Correct 58 ms 72024 KB Output is correct
59 Correct 58 ms 72024 KB Output is correct
60 Correct 57 ms 72016 KB Output is correct
61 Correct 54 ms 72016 KB Output is correct
62 Correct 33 ms 72028 KB Output is correct
63 Correct 56 ms 72020 KB Output is correct
64 Correct 83 ms 71976 KB Output is correct
65 Correct 48 ms 72024 KB Output is correct
66 Correct 74 ms 72028 KB Output is correct
67 Correct 58 ms 72028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 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 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 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 6492 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 129 ms 128704 KB Output is correct
14 Correct 134 ms 138236 KB Output is correct
15 Correct 174 ms 146768 KB Output is correct
16 Correct 245 ms 157812 KB Output is correct
17 Correct 278 ms 165612 KB Output is correct
18 Correct 273 ms 163920 KB Output is correct
19 Correct 273 ms 165460 KB Output is correct
20 Correct 1 ms 2392 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 4444 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 6488 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 6492 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 6748 KB Output is correct
39 Correct 1 ms 6748 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 6748 KB Output is correct
42 Correct 1 ms 6748 KB Output is correct
43 Correct 1 ms 6748 KB Output is correct
44 Correct 1 ms 6748 KB Output is correct
45 Correct 1 ms 6748 KB Output is correct
46 Correct 1 ms 6744 KB Output is correct
47 Correct 1 ms 6744 KB Output is correct
48 Correct 1 ms 6744 KB Output is correct
49 Correct 1 ms 6748 KB Output is correct
50 Correct 1 ms 6748 KB Output is correct
51 Correct 0 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 4444 KB Output is correct
55 Correct 1 ms 6576 KB Output is correct
56 Correct 1 ms 6748 KB Output is correct
57 Correct 2 ms 9052 KB Output is correct
58 Correct 3 ms 15824 KB Output is correct
59 Correct 4 ms 15708 KB Output is correct
60 Correct 4 ms 15704 KB Output is correct
61 Correct 4 ms 15708 KB Output is correct
62 Correct 4 ms 15708 KB Output is correct
63 Correct 3 ms 15708 KB Output is correct
64 Correct 3 ms 15704 KB Output is correct
65 Correct 4 ms 15840 KB Output is correct
66 Correct 3 ms 15708 KB Output is correct
67 Correct 3 ms 15708 KB Output is correct
68 Correct 3 ms 15708 KB Output is correct
69 Correct 3 ms 15824 KB Output is correct
70 Correct 3 ms 15708 KB Output is correct
71 Correct 16 ms 33912 KB Output is correct
72 Correct 37 ms 72028 KB Output is correct
73 Correct 59 ms 72028 KB Output is correct
74 Correct 68 ms 72080 KB Output is correct
75 Correct 58 ms 72024 KB Output is correct
76 Correct 58 ms 72024 KB Output is correct
77 Correct 57 ms 72016 KB Output is correct
78 Correct 54 ms 72016 KB Output is correct
79 Correct 33 ms 72028 KB Output is correct
80 Correct 56 ms 72020 KB Output is correct
81 Correct 83 ms 71976 KB Output is correct
82 Correct 48 ms 72024 KB Output is correct
83 Correct 74 ms 72028 KB Output is correct
84 Correct 58 ms 72028 KB Output is correct
85 Correct 172 ms 115208 KB Output is correct
86 Correct 411 ms 181348 KB Output is correct
87 Correct 437 ms 181048 KB Output is correct
88 Correct 397 ms 181072 KB Output is correct
89 Incorrect 373 ms 181328 KB Output isn't correct
90 Halted 0 ms 0 KB -