# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1096892 | 2024-10-05T11:24:48 Z | thangdz2k7 | Copy and Paste 3 (JOI22_copypaste3) | C++17 | 241 ms | 110296 KB |
// author : thembululquaUwU // 3.9.2024 #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define endl '\n' using namespace std; using ll = long long; using ii = pair <int, int>; using vi = vector <int>; const int N = 3e3; const int mod = 1e9 + 7; void maxl(auto &a, auto b) {a = max(a, b);} void minl(auto &a, auto b) {a = min(a, b);} #define next __next__ int n, a, b, c, f[N][N], next[N][N]; ll dp[N][N]; string s; void solve(){ cin >> n >> s; s = ' ' + s; cin >> a >> b >> c; for (int i = n; i >= 1; -- i){ for (int j = n; j > i; -- j) if (s[i] != s[j]) f[i][j] = 0; else f[i][j] = f[i + 1][j + 1] + 1; } for (int i = 0; i <= n + 1; ++ i){ for (int j = 0; j <= n + 1; ++ j){ if (i > j) dp[i][j] = 0; else dp[i][j] = ll(a) * (j - i + 1); next[i][j] = n + 2; } } for (int i = 1; i <= n; ++ i) { int jj = i + 1; for (int j = i; j <= n; ++ j){ if (jj > n) break; if (jj <= j || f[i][jj] < (j - i + 1)){ -- j; ++ jj; continue; } next[i][j - i + 1] = jj; } } for (int i = n; i >= 1; -- i){ for (int j = i; j <= n; ++ j){ minl(dp[i][j], min(dp[i + 1][j], dp[i][j - 1]) + a); int p = i, le = j - i + 1, d = 1; while (p < n + 1){ ++ d; p = next[p][le]; int r = p + le - 1; ll cost = ll(d) * c + b + ll(r - i + 1 - d * le) * a; minl(dp[i][r], dp[i][j] + cost); } } } cout << dp[1][n]; } int main(){ if (fopen("pqh.inp", "r")){ freopen("pqh.inp", "r", stdin); freopen("pqh.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t --) solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 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 | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 119 ms | 75964 KB | Output is correct |
4 | Correct | 132 ms | 84584 KB | Output is correct |
5 | Correct | 174 ms | 92756 KB | Output is correct |
6 | Correct | 173 ms | 101200 KB | Output is correct |
7 | Correct | 210 ms | 110236 KB | Output is correct |
8 | Correct | 241 ms | 110164 KB | Output is correct |
9 | Correct | 202 ms | 110164 KB | Output is correct |
10 | Correct | 0 ms | 344 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 604 KB | Output is correct |
16 | Correct | 1 ms | 600 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 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 | 348 KB | Output is correct |
11 | Correct | 0 ms | 600 KB | Output is correct |
12 | Correct | 0 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 604 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 600 KB | Output is correct |
16 | Correct | 0 ms | 604 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 604 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 860 KB | Output is correct |
22 | Correct | 0 ms | 604 KB | Output is correct |
23 | Correct | 0 ms | 860 KB | Output is correct |
24 | Correct | 0 ms | 856 KB | Output is correct |
25 | Correct | 1 ms | 604 KB | Output is correct |
26 | Correct | 0 ms | 604 KB | Output is correct |
27 | Correct | 0 ms | 720 KB | Output is correct |
28 | Correct | 0 ms | 860 KB | Output is correct |
29 | Correct | 0 ms | 860 KB | Output is correct |
30 | Correct | 0 ms | 860 KB | Output is correct |
31 | Correct | 0 ms | 604 KB | Output is correct |
32 | Correct | 0 ms | 860 KB | Output is correct |
33 | Correct | 0 ms | 928 KB | Output is correct |
34 | Correct | 0 ms | 464 KB | Output is correct |
35 | Correct | 0 ms | 348 KB | Output is correct |
36 | Correct | 0 ms | 344 KB | Output is correct |
37 | Correct | 0 ms | 348 KB | Output is correct |
38 | Correct | 1 ms | 604 KB | Output is correct |
39 | Correct | 0 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 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 | 348 KB | Output is correct |
11 | Correct | 0 ms | 600 KB | Output is correct |
12 | Correct | 0 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 604 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 600 KB | Output is correct |
16 | Correct | 0 ms | 604 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 604 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 860 KB | Output is correct |
22 | Correct | 0 ms | 604 KB | Output is correct |
23 | Correct | 0 ms | 860 KB | Output is correct |
24 | Correct | 0 ms | 856 KB | Output is correct |
25 | Correct | 1 ms | 604 KB | Output is correct |
26 | Correct | 0 ms | 604 KB | Output is correct |
27 | Correct | 0 ms | 720 KB | Output is correct |
28 | Correct | 0 ms | 860 KB | Output is correct |
29 | Correct | 0 ms | 860 KB | Output is correct |
30 | Correct | 0 ms | 860 KB | Output is correct |
31 | Correct | 0 ms | 604 KB | Output is correct |
32 | Correct | 0 ms | 860 KB | Output is correct |
33 | Correct | 0 ms | 928 KB | Output is correct |
34 | Correct | 0 ms | 464 KB | Output is correct |
35 | Correct | 0 ms | 348 KB | Output is correct |
36 | Correct | 0 ms | 344 KB | Output is correct |
37 | Correct | 0 ms | 348 KB | Output is correct |
38 | Correct | 1 ms | 604 KB | Output is correct |
39 | Correct | 0 ms | 604 KB | Output is correct |
40 | Correct | 1 ms | 1624 KB | Output is correct |
41 | Correct | 2 ms | 3524 KB | Output is correct |
42 | Correct | 1 ms | 3420 KB | Output is correct |
43 | Correct | 1 ms | 3420 KB | Output is correct |
44 | Correct | 1 ms | 3420 KB | Output is correct |
45 | Correct | 1 ms | 3420 KB | Output is correct |
46 | Correct | 1 ms | 3420 KB | Output is correct |
47 | Correct | 2 ms | 3420 KB | Output is correct |
48 | Correct | 1 ms | 3420 KB | Output is correct |
49 | Correct | 2 ms | 3420 KB | Output is correct |
50 | Correct | 1 ms | 3420 KB | Output is correct |
51 | Correct | 2 ms | 3416 KB | Output is correct |
52 | Correct | 2 ms | 3420 KB | Output is correct |
53 | Correct | 2 ms | 3420 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 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 | 348 KB | Output is correct |
11 | Correct | 0 ms | 600 KB | Output is correct |
12 | Correct | 0 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 604 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 600 KB | Output is correct |
16 | Correct | 0 ms | 604 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 604 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 860 KB | Output is correct |
22 | Correct | 0 ms | 604 KB | Output is correct |
23 | Correct | 0 ms | 860 KB | Output is correct |
24 | Correct | 0 ms | 856 KB | Output is correct |
25 | Correct | 1 ms | 604 KB | Output is correct |
26 | Correct | 0 ms | 604 KB | Output is correct |
27 | Correct | 0 ms | 720 KB | Output is correct |
28 | Correct | 0 ms | 860 KB | Output is correct |
29 | Correct | 0 ms | 860 KB | Output is correct |
30 | Correct | 0 ms | 860 KB | Output is correct |
31 | Correct | 0 ms | 604 KB | Output is correct |
32 | Correct | 0 ms | 860 KB | Output is correct |
33 | Correct | 0 ms | 928 KB | Output is correct |
34 | Correct | 0 ms | 464 KB | Output is correct |
35 | Correct | 0 ms | 348 KB | Output is correct |
36 | Correct | 0 ms | 344 KB | Output is correct |
37 | Correct | 0 ms | 348 KB | Output is correct |
38 | Correct | 1 ms | 604 KB | Output is correct |
39 | Correct | 0 ms | 604 KB | Output is correct |
40 | Correct | 1 ms | 1624 KB | Output is correct |
41 | Correct | 2 ms | 3524 KB | Output is correct |
42 | Correct | 1 ms | 3420 KB | Output is correct |
43 | Correct | 1 ms | 3420 KB | Output is correct |
44 | Correct | 1 ms | 3420 KB | Output is correct |
45 | Correct | 1 ms | 3420 KB | Output is correct |
46 | Correct | 1 ms | 3420 KB | Output is correct |
47 | Correct | 2 ms | 3420 KB | Output is correct |
48 | Correct | 1 ms | 3420 KB | Output is correct |
49 | Correct | 2 ms | 3420 KB | Output is correct |
50 | Correct | 1 ms | 3420 KB | Output is correct |
51 | Correct | 2 ms | 3416 KB | Output is correct |
52 | Correct | 2 ms | 3420 KB | Output is correct |
53 | Correct | 2 ms | 3420 KB | Output is correct |
54 | Correct | 4 ms | 9308 KB | Output is correct |
55 | Correct | 29 ms | 30116 KB | Output is correct |
56 | Correct | 17 ms | 30044 KB | Output is correct |
57 | Correct | 19 ms | 30044 KB | Output is correct |
58 | Correct | 16 ms | 30040 KB | Output is correct |
59 | Correct | 15 ms | 30044 KB | Output is correct |
60 | Correct | 14 ms | 30044 KB | Output is correct |
61 | Correct | 15 ms | 30044 KB | Output is correct |
62 | Correct | 25 ms | 30036 KB | Output is correct |
63 | Correct | 15 ms | 30044 KB | Output is correct |
64 | Correct | 16 ms | 30160 KB | Output is correct |
65 | Correct | 19 ms | 30040 KB | Output is correct |
66 | Correct | 23 ms | 30036 KB | Output is correct |
67 | Correct | 15 ms | 30060 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 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 | 348 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 119 ms | 75964 KB | Output is correct |
14 | Correct | 132 ms | 84584 KB | Output is correct |
15 | Correct | 174 ms | 92756 KB | Output is correct |
16 | Correct | 173 ms | 101200 KB | Output is correct |
17 | Correct | 210 ms | 110236 KB | Output is correct |
18 | Correct | 241 ms | 110164 KB | Output is correct |
19 | Correct | 202 ms | 110164 KB | Output is correct |
20 | Correct | 0 ms | 344 KB | Output is correct |
21 | Correct | 1 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 344 KB | Output is correct |
23 | Correct | 0 ms | 348 KB | Output is correct |
24 | Correct | 0 ms | 348 KB | Output is correct |
25 | Correct | 0 ms | 604 KB | Output is correct |
26 | Correct | 1 ms | 600 KB | Output is correct |
27 | Correct | 0 ms | 348 KB | Output is correct |
28 | Correct | 0 ms | 600 KB | Output is correct |
29 | Correct | 0 ms | 604 KB | Output is correct |
30 | Correct | 0 ms | 604 KB | Output is correct |
31 | Correct | 0 ms | 348 KB | Output is correct |
32 | Correct | 1 ms | 600 KB | Output is correct |
33 | Correct | 0 ms | 604 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 | 604 KB | Output is correct |
37 | Correct | 0 ms | 348 KB | Output is correct |
38 | Correct | 0 ms | 860 KB | Output is correct |
39 | Correct | 0 ms | 604 KB | Output is correct |
40 | Correct | 0 ms | 860 KB | Output is correct |
41 | Correct | 0 ms | 856 KB | Output is correct |
42 | Correct | 1 ms | 604 KB | Output is correct |
43 | Correct | 0 ms | 604 KB | Output is correct |
44 | Correct | 0 ms | 720 KB | Output is correct |
45 | Correct | 0 ms | 860 KB | Output is correct |
46 | Correct | 0 ms | 860 KB | Output is correct |
47 | Correct | 0 ms | 860 KB | Output is correct |
48 | Correct | 0 ms | 604 KB | Output is correct |
49 | Correct | 0 ms | 860 KB | Output is correct |
50 | Correct | 0 ms | 928 KB | Output is correct |
51 | Correct | 0 ms | 464 KB | Output is correct |
52 | Correct | 0 ms | 348 KB | Output is correct |
53 | Correct | 0 ms | 344 KB | Output is correct |
54 | Correct | 0 ms | 348 KB | Output is correct |
55 | Correct | 1 ms | 604 KB | Output is correct |
56 | Correct | 0 ms | 604 KB | Output is correct |
57 | Correct | 1 ms | 1624 KB | Output is correct |
58 | Correct | 2 ms | 3524 KB | Output is correct |
59 | Correct | 1 ms | 3420 KB | Output is correct |
60 | Correct | 1 ms | 3420 KB | Output is correct |
61 | Correct | 1 ms | 3420 KB | Output is correct |
62 | Correct | 1 ms | 3420 KB | Output is correct |
63 | Correct | 1 ms | 3420 KB | Output is correct |
64 | Correct | 2 ms | 3420 KB | Output is correct |
65 | Correct | 1 ms | 3420 KB | Output is correct |
66 | Correct | 2 ms | 3420 KB | Output is correct |
67 | Correct | 1 ms | 3420 KB | Output is correct |
68 | Correct | 2 ms | 3416 KB | Output is correct |
69 | Correct | 2 ms | 3420 KB | Output is correct |
70 | Correct | 2 ms | 3420 KB | Output is correct |
71 | Correct | 4 ms | 9308 KB | Output is correct |
72 | Correct | 29 ms | 30116 KB | Output is correct |
73 | Correct | 17 ms | 30044 KB | Output is correct |
74 | Correct | 19 ms | 30044 KB | Output is correct |
75 | Correct | 16 ms | 30040 KB | Output is correct |
76 | Correct | 15 ms | 30044 KB | Output is correct |
77 | Correct | 14 ms | 30044 KB | Output is correct |
78 | Correct | 15 ms | 30044 KB | Output is correct |
79 | Correct | 25 ms | 30036 KB | Output is correct |
80 | Correct | 15 ms | 30044 KB | Output is correct |
81 | Correct | 16 ms | 30160 KB | Output is correct |
82 | Correct | 19 ms | 30040 KB | Output is correct |
83 | Correct | 23 ms | 30036 KB | Output is correct |
84 | Correct | 15 ms | 30060 KB | Output is correct |
85 | Correct | 41 ms | 61540 KB | Output is correct |
86 | Correct | 84 ms | 110160 KB | Output is correct |
87 | Correct | 77 ms | 110164 KB | Output is correct |
88 | Correct | 67 ms | 110160 KB | Output is correct |
89 | Correct | 65 ms | 110292 KB | Output is correct |
90 | Correct | 62 ms | 110292 KB | Output is correct |
91 | Correct | 93 ms | 110116 KB | Output is correct |
92 | Correct | 119 ms | 110164 KB | Output is correct |
93 | Correct | 67 ms | 110296 KB | Output is correct |
94 | Correct | 70 ms | 110164 KB | Output is correct |
95 | Correct | 113 ms | 110172 KB | Output is correct |
96 | Correct | 117 ms | 110112 KB | Output is correct |
97 | Correct | 62 ms | 110164 KB | Output is correct |