Submission #1036434

# Submission time Handle Problem Language Result Execution time Memory
1036434 2024-07-27T11:02:05 Z aymanrs Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
559 ms 348868 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> z_func(const string& s){
    int n = s.size();
    vector<int> z(n, 0);
    int l = 0, r = 0;
    for(int i = 1;i < n;i++){
        if(i<r) z[i] = min(z[i-l], r-i);
        if(z[i]+i>=r){
            while(z[i]+i<n && s[z[i]+i] == s[z[i]]) z[i]++;
            r = z[i]+i;
            l = i;
        }
    }
    return z;
}
struct up {
    int i, j, c;
};
void solve(){
    int n;long long a,b,C;string s;
    cin >> n >> s >> a >> b >> C;
    long long dp[n+1][n+1];
    int nxr[n][n];
    vector<int> Z[n];
    long long L[n] = {0};
    vector<up> upd[n];
    for(int i = n-1;i >= 0;i--){
        Z[i] = z_func(s.substr(i));
        nxr[i][i]=find(s.begin()+i+1, s.end(), s[i])-s.begin();
        for(int j = i+1;j < n;j++){
            nxr[i][j] = nxr[i][j-1];
            while(nxr[i][j] < n && (nxr[i][j]<=j || Z[i][nxr[i][j]-i] < (j-i+1))) nxr[i][j]++;
        }
        for(int j = i;j < n;j++){
            if(nxr[i][j] >= n) break;
            int cj = nxr[i][j];up u = {i,j,1};
            while(cj<n){
                u.c++;
                upd[cj+j-i].push_back(u);
                cj = nxr[cj][cj+j-i];
            }
        }
    }
    for(int R = 0;R < n;R++){
        for(auto [i,j,c] : upd[R]){
            L[i] = max(L[i], -dp[i][j]-b+(a*(j-i+1)-C)*c);
        }
        for(int i = R-1;i >= 0;i--) L[i] = max(L[i], L[i+1]);
        for(int i = 0;i <= R;i++) dp[i][R] = a*(R-i+1)-L[i];
    }
    cout << dp[0][n-1] << '\n';;
}   
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 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 604 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 279 ms 189264 KB Output is correct
4 Correct 324 ms 219728 KB Output is correct
5 Correct 402 ms 256040 KB Output is correct
6 Correct 435 ms 298320 KB Output is correct
7 Correct 559 ms 348868 KB Output is correct
8 Correct 557 ms 348748 KB Output is correct
9 Correct 546 ms 348584 KB Output is correct
10 Correct 0 ms 344 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 348 KB Output is correct
14 Correct 0 ms 604 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 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 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 604 KB Output is correct
9 Correct 0 ms 452 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 460 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 344 KB Output is correct
18 Correct 1 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 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 1 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 600 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 0 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 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 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 604 KB Output is correct
9 Correct 0 ms 452 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 460 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 344 KB Output is correct
18 Correct 1 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 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 1 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 600 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 0 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 604 KB Output is correct
41 Correct 2 ms 2140 KB Output is correct
42 Correct 2 ms 1116 KB Output is correct
43 Correct 1 ms 1116 KB Output is correct
44 Correct 1 ms 968 KB Output is correct
45 Correct 1 ms 968 KB Output is correct
46 Correct 1 ms 1116 KB Output is correct
47 Correct 1 ms 1372 KB Output is correct
48 Correct 1 ms 1116 KB Output is correct
49 Correct 1 ms 1116 KB Output is correct
50 Correct 1 ms 1116 KB Output is correct
51 Correct 1 ms 1372 KB Output is correct
52 Correct 1 ms 1372 KB Output is correct
53 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 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 604 KB Output is correct
9 Correct 0 ms 452 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 460 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 344 KB Output is correct
18 Correct 1 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 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 1 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 600 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 0 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 604 KB Output is correct
41 Correct 2 ms 2140 KB Output is correct
42 Correct 2 ms 1116 KB Output is correct
43 Correct 1 ms 1116 KB Output is correct
44 Correct 1 ms 968 KB Output is correct
45 Correct 1 ms 968 KB Output is correct
46 Correct 1 ms 1116 KB Output is correct
47 Correct 1 ms 1372 KB Output is correct
48 Correct 1 ms 1116 KB Output is correct
49 Correct 1 ms 1116 KB Output is correct
50 Correct 1 ms 1116 KB Output is correct
51 Correct 1 ms 1372 KB Output is correct
52 Correct 1 ms 1372 KB Output is correct
53 Correct 1 ms 860 KB Output is correct
54 Correct 5 ms 4700 KB Output is correct
55 Correct 65 ms 53820 KB Output is correct
56 Correct 22 ms 21852 KB Output is correct
57 Correct 17 ms 18292 KB Output is correct
58 Correct 13 ms 15964 KB Output is correct
59 Correct 14 ms 14940 KB Output is correct
60 Correct 13 ms 14428 KB Output is correct
61 Correct 15 ms 19528 KB Output is correct
62 Correct 50 ms 46884 KB Output is correct
63 Correct 15 ms 18268 KB Output is correct
64 Correct 18 ms 20632 KB Output is correct
65 Correct 33 ms 32596 KB Output is correct
66 Correct 36 ms 32348 KB Output is correct
67 Correct 10 ms 14424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 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 604 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 279 ms 189264 KB Output is correct
14 Correct 324 ms 219728 KB Output is correct
15 Correct 402 ms 256040 KB Output is correct
16 Correct 435 ms 298320 KB Output is correct
17 Correct 559 ms 348868 KB Output is correct
18 Correct 557 ms 348748 KB Output is correct
19 Correct 546 ms 348584 KB Output is correct
20 Correct 0 ms 344 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 348 KB Output is correct
24 Correct 0 ms 604 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 460 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 344 KB Output is correct
35 Correct 1 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 348 KB Output is correct
40 Correct 1 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 1 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 600 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 0 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 604 KB Output is correct
58 Correct 2 ms 2140 KB Output is correct
59 Correct 2 ms 1116 KB Output is correct
60 Correct 1 ms 1116 KB Output is correct
61 Correct 1 ms 968 KB Output is correct
62 Correct 1 ms 968 KB Output is correct
63 Correct 1 ms 1116 KB Output is correct
64 Correct 1 ms 1372 KB Output is correct
65 Correct 1 ms 1116 KB Output is correct
66 Correct 1 ms 1116 KB Output is correct
67 Correct 1 ms 1116 KB Output is correct
68 Correct 1 ms 1372 KB Output is correct
69 Correct 1 ms 1372 KB Output is correct
70 Correct 1 ms 860 KB Output is correct
71 Correct 5 ms 4700 KB Output is correct
72 Correct 65 ms 53820 KB Output is correct
73 Correct 22 ms 21852 KB Output is correct
74 Correct 17 ms 18292 KB Output is correct
75 Correct 13 ms 15964 KB Output is correct
76 Correct 14 ms 14940 KB Output is correct
77 Correct 13 ms 14428 KB Output is correct
78 Correct 15 ms 19528 KB Output is correct
79 Correct 50 ms 46884 KB Output is correct
80 Correct 15 ms 18268 KB Output is correct
81 Correct 18 ms 20632 KB Output is correct
82 Correct 33 ms 32596 KB Output is correct
83 Correct 36 ms 32348 KB Output is correct
84 Correct 10 ms 14424 KB Output is correct
85 Correct 56 ms 53076 KB Output is correct
86 Correct 158 ms 130640 KB Output is correct
87 Correct 118 ms 110416 KB Output is correct
88 Correct 87 ms 96120 KB Output is correct
89 Correct 74 ms 90772 KB Output is correct
90 Correct 71 ms 88912 KB Output is correct
91 Correct 229 ms 194896 KB Output is correct
92 Correct 324 ms 263760 KB Output is correct
93 Correct 105 ms 112724 KB Output is correct
94 Correct 115 ms 124500 KB Output is correct
95 Correct 278 ms 221780 KB Output is correct
96 Correct 299 ms 221008 KB Output is correct
97 Correct 68 ms 88896 KB Output is correct