답안 #1031242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031242 2024-07-22T16:23:06 Z adaawf Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
392 ms 69764 KB
#include <iostream>
#include <map>
using namespace std;
long long int c[3005], p[3005], f[3005][3005], g[3005][3005], mod = 1e9 + 7, b = 177013;
long long int cc[3005], pp[3005], bb = 228922;
long long int check(int i, int j) {
    return (c[j] - c[i - 1] * p[j - i + 1] % mod + mod) % mod;
}
long long int check2(int i, int j) {
    return (cc[j] - cc[i - 1] * pp[j - i + 1] % mod + mod) % mod;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long int n, x, y, z;
    string s;
    cin >> n >> s >> x >> y >> z;
    s = " " + s;
    p[0] = pp[0] = 1;
    for (int i = 1; i <= n; i++) {
        c[i] = (c[i - 1] * b + s[i] - 'a' + 1) % mod;
        cc[i] = (cc[i - 1] * bb + s[i] - 'a' + 1) % mod;
        p[i] = p[i - 1] * b % mod;
        pp[i] = pp[i - 1] * bb % mod;
    }
    for (int d = 1; d <= n; d++) {
        map<pair<long long int, long long int>, int> m;
        for (int i = n - d + 1; i >= 1; i--) {
            int j = i + d - 1;
            g[i][j] = 1e18;
            long long int h = check(i, j), k = check2(i, j);
            if (m.count({h, k})) f[i][j] = m[{h, k}];
            else f[i][j] = 0;
            if (j + d - 1 <= n) m[{check(j, j + d - 1), check2(j, j + d - 1)}] = j;
        }
    }
    for (int d = 1; d <= n; d++) {
        for (int i = 1; i <= n - d + 1; i++) {
            int j = i + d - 1;
            g[i][j] = min(g[i][j], x * d);
            g[i][j] = min(g[i][j], min(g[i + 1][j], g[i][j - 1]) + x);
            int h = i, l = 1;
            while (1) {
                h = f[h][h + d - 1];
                if (h == 0) break;
                int k = h + d - 1;
                l++;
                g[i][k] = min(g[i][k], g[i][j] + y + x * (k - i + 1 - l * d) + l * z);
            }
        }
    }
    cout << g[1][n];
}
# 결과 실행 시간 메모리 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 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 114 ms 41400 KB Output is correct
4 Correct 130 ms 46952 KB Output is correct
5 Correct 172 ms 53588 KB Output is correct
6 Correct 198 ms 60756 KB Output is correct
7 Correct 229 ms 69560 KB Output is correct
8 Correct 244 ms 69564 KB Output is correct
9 Correct 229 ms 69460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 528 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 604 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 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 392 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 716 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 0 ms 604 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 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 600 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 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 392 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 716 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 0 ms 604 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 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 600 KB Output is correct
40 Correct 1 ms 1112 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 2 ms 2396 KB Output is correct
43 Correct 2 ms 2396 KB Output is correct
44 Correct 2 ms 2396 KB Output is correct
45 Correct 2 ms 2368 KB Output is correct
46 Correct 2 ms 2256 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 2 ms 2392 KB Output is correct
49 Correct 2 ms 2392 KB Output is correct
50 Correct 3 ms 2396 KB Output is correct
51 Correct 2 ms 2396 KB Output is correct
52 Correct 2 ms 2396 KB Output is correct
53 Correct 3 ms 2396 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 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 392 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 716 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 0 ms 604 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 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 600 KB Output is correct
40 Correct 1 ms 1112 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 2 ms 2396 KB Output is correct
43 Correct 2 ms 2396 KB Output is correct
44 Correct 2 ms 2396 KB Output is correct
45 Correct 2 ms 2368 KB Output is correct
46 Correct 2 ms 2256 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 2 ms 2392 KB Output is correct
49 Correct 2 ms 2392 KB Output is correct
50 Correct 3 ms 2396 KB Output is correct
51 Correct 2 ms 2396 KB Output is correct
52 Correct 2 ms 2396 KB Output is correct
53 Correct 3 ms 2396 KB Output is correct
54 Correct 10 ms 5464 KB Output is correct
55 Correct 29 ms 16180 KB Output is correct
56 Correct 56 ms 16220 KB Output is correct
57 Correct 54 ms 16420 KB Output is correct
58 Correct 50 ms 16208 KB Output is correct
59 Correct 56 ms 16292 KB Output is correct
60 Correct 51 ms 16208 KB Output is correct
61 Correct 46 ms 16344 KB Output is correct
62 Correct 27 ms 16220 KB Output is correct
63 Correct 52 ms 16224 KB Output is correct
64 Correct 49 ms 16212 KB Output is correct
65 Correct 46 ms 16232 KB Output is correct
66 Correct 46 ms 16212 KB Output is correct
67 Correct 55 ms 16460 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 1 ms 604 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 344 KB Output is correct
13 Correct 114 ms 41400 KB Output is correct
14 Correct 130 ms 46952 KB Output is correct
15 Correct 172 ms 53588 KB Output is correct
16 Correct 198 ms 60756 KB Output is correct
17 Correct 229 ms 69560 KB Output is correct
18 Correct 244 ms 69564 KB Output is correct
19 Correct 229 ms 69460 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 528 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 460 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 392 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 604 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 0 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 0 ms 604 KB Output is correct
43 Correct 0 ms 604 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 0 ms 716 KB Output is correct
47 Correct 0 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 0 ms 604 KB Output is correct
50 Correct 0 ms 604 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 600 KB Output is correct
57 Correct 1 ms 1112 KB Output is correct
58 Correct 2 ms 2396 KB Output is correct
59 Correct 2 ms 2396 KB Output is correct
60 Correct 2 ms 2396 KB Output is correct
61 Correct 2 ms 2396 KB Output is correct
62 Correct 2 ms 2368 KB Output is correct
63 Correct 2 ms 2256 KB Output is correct
64 Correct 2 ms 2396 KB Output is correct
65 Correct 2 ms 2392 KB Output is correct
66 Correct 2 ms 2392 KB Output is correct
67 Correct 3 ms 2396 KB Output is correct
68 Correct 2 ms 2396 KB Output is correct
69 Correct 2 ms 2396 KB Output is correct
70 Correct 3 ms 2396 KB Output is correct
71 Correct 10 ms 5464 KB Output is correct
72 Correct 29 ms 16180 KB Output is correct
73 Correct 56 ms 16220 KB Output is correct
74 Correct 54 ms 16420 KB Output is correct
75 Correct 50 ms 16208 KB Output is correct
76 Correct 56 ms 16292 KB Output is correct
77 Correct 51 ms 16208 KB Output is correct
78 Correct 46 ms 16344 KB Output is correct
79 Correct 27 ms 16220 KB Output is correct
80 Correct 52 ms 16224 KB Output is correct
81 Correct 49 ms 16212 KB Output is correct
82 Correct 46 ms 16232 KB Output is correct
83 Correct 46 ms 16212 KB Output is correct
84 Correct 55 ms 16460 KB Output is correct
85 Correct 146 ms 32856 KB Output is correct
86 Correct 365 ms 69656 KB Output is correct
87 Correct 382 ms 69716 KB Output is correct
88 Correct 356 ms 69716 KB Output is correct
89 Correct 352 ms 69764 KB Output is correct
90 Correct 362 ms 69720 KB Output is correct
91 Correct 221 ms 69568 KB Output is correct
92 Correct 204 ms 69460 KB Output is correct
93 Correct 374 ms 69604 KB Output is correct
94 Correct 361 ms 69620 KB Output is correct
95 Correct 373 ms 69476 KB Output is correct
96 Correct 392 ms 69460 KB Output is correct
97 Correct 354 ms 69572 KB Output is correct