Submission #997379

# Submission time Handle Problem Language Result Execution time Memory
997379 2024-06-12T08:13:57 Z onbert Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
775 ms 98820 KB
//bruhed
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, A, B, C;
    string s;
    cin >> n >> s >> A >> B >> C;
    s = '.' + s;
    int id[n+1][n+2], cost[n+1][n+2];
    for (int i=0;i<=n;i++) for (int j=1;j<=n+1;j++) id[i][j] = -1, cost[i][j] = INF;
    for (int i=1;i<=n;i++) cost[1][i] = A;

    for (int sz=1;sz<=n;sz++) {
        // cout << sz << endl;
        if (sz!=1) {
            for (int i=1;i<=n-sz+1;i++) {
                cost[sz][i] = min(cost[sz-1][i] + A, cost[sz][i]);
                cost[sz][i] = min(cost[sz-1][i+1] + A, cost[sz][i]);
                // cout << cost[sz][i] << " ";
            }
        }
        // cout << endl;
        vector<pair<char,int>> v = {{' ', -1}};
        for (int i=1;i<=n-sz+1;i++) v.push_back({s[i], id[sz-1][i+1]});
        sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
        int m = v.size() - 1;
        vector<int> mem[m+1];
        for (int i=1;i<=n-sz+1;i++) {
            id[sz][i] = lower_bound(v.begin(), v.end(), make_pair(s[i], id[sz-1][i+1])) - v.begin();
            mem[id[sz][i]].push_back(i);
        }
        for (int i=1;i<=m;i++) mem[i].push_back(INF);
        for (int i=1;i<=m;i++) {
            for (int J=0;J<(int)mem[i].size()-1;J++) {
                int j = mem[i][J];
                int last = j;
                for (int cnt = 2; ;cnt++) {
                    if (J+cnt-1 > (int)mem[i].size()-1) break;
                    int nxt = max(*lower_bound(mem[i].begin(), mem[i].end(), last + sz), mem[i][J+cnt-1]);
                    if (nxt==INF) break;
                    int SZ = nxt + sz - j;
                    int val = (SZ - cnt*sz)*A + C*cnt + cost[sz][j] + B;
                    // if (SZ == 3 && j == 4) cout << "test " << cnt << " " << val << endl;
                    cost[SZ][j] = min(val, cost[SZ][j]);
                    last = nxt;
                }
            }
        }
    }
    cout << cost[n][1] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 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 344 KB Output is correct
7 Correct 0 ms 344 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 353 ms 52820 KB Output is correct
4 Correct 433 ms 61784 KB Output is correct
5 Correct 524 ms 72016 KB Output is correct
6 Correct 641 ms 84308 KB Output is correct
7 Correct 775 ms 98260 KB Output is correct
8 Correct 766 ms 98384 KB Output is correct
9 Correct 737 ms 98384 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 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 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 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 344 KB Output is correct
7 Correct 0 ms 344 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 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 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 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 348 KB Output is correct
26 Correct 0 ms 348 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 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 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 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 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 344 KB Output is correct
7 Correct 0 ms 344 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 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 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 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 348 KB Output is correct
26 Correct 0 ms 348 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 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 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 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 3 ms 856 KB Output is correct
42 Correct 5 ms 1112 KB Output is correct
43 Correct 5 ms 1112 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 4 ms 860 KB Output is correct
46 Correct 4 ms 860 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 3 ms 860 KB Output is correct
49 Correct 3 ms 1112 KB Output is correct
50 Correct 4 ms 860 KB Output is correct
51 Correct 3 ms 860 KB Output is correct
52 Correct 4 ms 860 KB Output is correct
53 Correct 4 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 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 344 KB Output is correct
7 Correct 0 ms 344 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 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 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 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 348 KB Output is correct
26 Correct 0 ms 348 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 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 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 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 3 ms 856 KB Output is correct
42 Correct 5 ms 1112 KB Output is correct
43 Correct 5 ms 1112 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 4 ms 860 KB Output is correct
46 Correct 4 ms 860 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 3 ms 860 KB Output is correct
49 Correct 3 ms 1112 KB Output is correct
50 Correct 4 ms 860 KB Output is correct
51 Correct 3 ms 860 KB Output is correct
52 Correct 4 ms 860 KB Output is correct
53 Correct 4 ms 860 KB Output is correct
54 Correct 18 ms 3420 KB Output is correct
55 Correct 93 ms 16176 KB Output is correct
56 Correct 102 ms 16220 KB Output is correct
57 Correct 119 ms 16220 KB Output is correct
58 Correct 94 ms 16220 KB Output is correct
59 Correct 98 ms 16220 KB Output is correct
60 Correct 97 ms 16220 KB Output is correct
61 Correct 83 ms 16220 KB Output is correct
62 Correct 56 ms 15964 KB Output is correct
63 Correct 97 ms 16220 KB Output is correct
64 Correct 91 ms 16216 KB Output is correct
65 Correct 89 ms 16196 KB Output is correct
66 Correct 88 ms 16220 KB Output is correct
67 Correct 94 ms 16216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 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 344 KB Output is correct
7 Correct 0 ms 344 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 348 KB Output is correct
13 Correct 353 ms 52820 KB Output is correct
14 Correct 433 ms 61784 KB Output is correct
15 Correct 524 ms 72016 KB Output is correct
16 Correct 641 ms 84308 KB Output is correct
17 Correct 775 ms 98260 KB Output is correct
18 Correct 766 ms 98384 KB Output is correct
19 Correct 737 ms 98384 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 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 348 KB Output is correct
26 Correct 0 ms 348 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 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 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 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 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 1 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 3 ms 856 KB Output is correct
59 Correct 5 ms 1112 KB Output is correct
60 Correct 5 ms 1112 KB Output is correct
61 Correct 4 ms 860 KB Output is correct
62 Correct 4 ms 860 KB Output is correct
63 Correct 4 ms 860 KB Output is correct
64 Correct 2 ms 860 KB Output is correct
65 Correct 3 ms 860 KB Output is correct
66 Correct 3 ms 1112 KB Output is correct
67 Correct 4 ms 860 KB Output is correct
68 Correct 3 ms 860 KB Output is correct
69 Correct 4 ms 860 KB Output is correct
70 Correct 4 ms 860 KB Output is correct
71 Correct 18 ms 3420 KB Output is correct
72 Correct 93 ms 16176 KB Output is correct
73 Correct 102 ms 16220 KB Output is correct
74 Correct 119 ms 16220 KB Output is correct
75 Correct 94 ms 16220 KB Output is correct
76 Correct 98 ms 16220 KB Output is correct
77 Correct 97 ms 16220 KB Output is correct
78 Correct 83 ms 16220 KB Output is correct
79 Correct 56 ms 15964 KB Output is correct
80 Correct 97 ms 16220 KB Output is correct
81 Correct 91 ms 16216 KB Output is correct
82 Correct 89 ms 16196 KB Output is correct
83 Correct 88 ms 16220 KB Output is correct
84 Correct 94 ms 16216 KB Output is correct
85 Correct 255 ms 39760 KB Output is correct
86 Correct 687 ms 98640 KB Output is correct
87 Correct 674 ms 98464 KB Output is correct
88 Correct 660 ms 98640 KB Output is correct
89 Correct 643 ms 98644 KB Output is correct
90 Correct 636 ms 98672 KB Output is correct
91 Correct 419 ms 98624 KB Output is correct
92 Correct 384 ms 98384 KB Output is correct
93 Correct 650 ms 98640 KB Output is correct
94 Correct 654 ms 98820 KB Output is correct
95 Correct 661 ms 98604 KB Output is correct
96 Correct 610 ms 98524 KB Output is correct
97 Correct 605 ms 98640 KB Output is correct