Submission #1014308

# Submission time Handle Problem Language Result Execution time Memory
1014308 2024-07-04T16:20:59 Z Aiperiii Copy and Paste 3 (JOI22_copypaste3) C++14
62 / 100
1232 ms 97508 KB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N=2505,mod=1e9+7;
int h[N][N],dp[N][N];
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,a,b,c;
    cin>>n;
    string s;
    cin>>s;
    cin>>a>>b>>c;
    for(int i=0;i<n;i++){
        h[i][i]=s[i]-'a';
        //cout<<h[i][i]<<" ";
        for(int j=i+1;j<n;j++){
            h[i][j]=h[i][j-1]*31+(s[j]-'a');
            h[i][j]%=mod;
            //cout<<h[i][j]<<" ";
        }
        //cout<<"\n";
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i][j]=1e18;
        }
        dp[i][i]=a;
    }
    for(int sz=1;sz<=n;sz++){
        vector <pair <int,int> > v;
        for(int l=0;l<=n-sz;l++){
            int r=l+sz-1;
            dp[l][r]=min(dp[l][r],min(dp[l+1][r],dp[l][r-1])+a);
            v.pb({h[l][r],l});
        }
        sort(all(v));
        for(auto x : v){
            int pos=x.ss;
            int hash=x.ff;
            int cnt=1;
            while(true){
                pair <int,int> p={hash,pos+sz};
                auto it=lower_bound(all(v),p);
                if(it!=v.end() && it->ff==hash){
                    pos=it->ss;
                    cnt++;
                    dp[x.ss][pos+sz-1]=min(dp[x.ss][pos+sz-1],dp[x.ss][x.ss+sz-1]+b+c*cnt+a*(pos+sz-x.ss-sz*cnt));
                }
                else break;
            }
        }
        
    }
    cout<<dp[0][n-1]<<"\n";
}

/*
 2 5 4 9 15 11
 6 7 6 8 12 14
 1 0 0 0
 1 0 0 0
 0 0 0 0
 0 1 0 0
 0 1 1 0
 0 0 0 0

 0 1 0 0
 0 1 1 0
 0 1 0 0
 0 0 1 0
 0 0 1 1
 0 0 0 1
*/



# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 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 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 506 ms 68008 KB Output is correct
4 Correct 680 ms 72540 KB Output is correct
5 Correct 878 ms 87608 KB Output is correct
6 Correct 993 ms 88520 KB Output is correct
7 Correct 1216 ms 94544 KB Output is correct
8 Correct 1223 ms 90740 KB Output is correct
9 Correct 1232 ms 95824 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 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 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 4444 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 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6740 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 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 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 4444 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 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6740 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 2 ms 3164 KB Output is correct
41 Correct 4 ms 10588 KB Output is correct
42 Correct 2 ms 10588 KB Output is correct
43 Correct 3 ms 10588 KB Output is correct
44 Correct 2 ms 2396 KB Output is correct
45 Correct 3 ms 10588 KB Output is correct
46 Correct 2 ms 10588 KB Output is correct
47 Correct 4 ms 10588 KB Output is correct
48 Correct 3 ms 10584 KB Output is correct
49 Correct 3 ms 10588 KB Output is correct
50 Correct 3 ms 10588 KB Output is correct
51 Correct 3 ms 10588 KB Output is correct
52 Correct 4 ms 10600 KB Output is correct
53 Correct 2 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 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 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 4444 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 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6740 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 2 ms 3164 KB Output is correct
41 Correct 4 ms 10588 KB Output is correct
42 Correct 2 ms 10588 KB Output is correct
43 Correct 3 ms 10588 KB Output is correct
44 Correct 2 ms 2396 KB Output is correct
45 Correct 3 ms 10588 KB Output is correct
46 Correct 2 ms 10588 KB Output is correct
47 Correct 4 ms 10588 KB Output is correct
48 Correct 3 ms 10584 KB Output is correct
49 Correct 3 ms 10588 KB Output is correct
50 Correct 3 ms 10588 KB Output is correct
51 Correct 3 ms 10588 KB Output is correct
52 Correct 4 ms 10600 KB Output is correct
53 Correct 2 ms 10584 KB Output is correct
54 Correct 11 ms 22872 KB Output is correct
55 Correct 90 ms 43612 KB Output is correct
56 Correct 49 ms 39536 KB Output is correct
57 Correct 46 ms 43612 KB Output is correct
58 Correct 44 ms 38744 KB Output is correct
59 Correct 41 ms 43612 KB Output is correct
60 Correct 43 ms 39768 KB Output is correct
61 Correct 64 ms 43612 KB Output is correct
62 Correct 87 ms 43660 KB Output is correct
63 Correct 67 ms 38128 KB Output is correct
64 Correct 67 ms 43612 KB Output is correct
65 Correct 78 ms 43612 KB Output is correct
66 Correct 81 ms 43612 KB Output is correct
67 Correct 40 ms 42080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 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 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 506 ms 68008 KB Output is correct
14 Correct 680 ms 72540 KB Output is correct
15 Correct 878 ms 87608 KB Output is correct
16 Correct 993 ms 88520 KB Output is correct
17 Correct 1216 ms 94544 KB Output is correct
18 Correct 1223 ms 90740 KB Output is correct
19 Correct 1232 ms 95824 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 4444 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 4444 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6740 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 2 ms 6488 KB Output is correct
51 Correct 1 ms 2392 KB Output is correct
52 Correct 1 ms 2392 KB Output is correct
53 Correct 1 ms 2392 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 2 ms 3164 KB Output is correct
58 Correct 4 ms 10588 KB Output is correct
59 Correct 2 ms 10588 KB Output is correct
60 Correct 3 ms 10588 KB Output is correct
61 Correct 2 ms 2396 KB Output is correct
62 Correct 3 ms 10588 KB Output is correct
63 Correct 2 ms 10588 KB Output is correct
64 Correct 4 ms 10588 KB Output is correct
65 Correct 3 ms 10584 KB Output is correct
66 Correct 3 ms 10588 KB Output is correct
67 Correct 3 ms 10588 KB Output is correct
68 Correct 3 ms 10588 KB Output is correct
69 Correct 4 ms 10600 KB Output is correct
70 Correct 2 ms 10584 KB Output is correct
71 Correct 11 ms 22872 KB Output is correct
72 Correct 90 ms 43612 KB Output is correct
73 Correct 49 ms 39536 KB Output is correct
74 Correct 46 ms 43612 KB Output is correct
75 Correct 44 ms 38744 KB Output is correct
76 Correct 41 ms 43612 KB Output is correct
77 Correct 43 ms 39768 KB Output is correct
78 Correct 64 ms 43612 KB Output is correct
79 Correct 87 ms 43660 KB Output is correct
80 Correct 67 ms 38128 KB Output is correct
81 Correct 67 ms 43612 KB Output is correct
82 Correct 78 ms 43612 KB Output is correct
83 Correct 81 ms 43612 KB Output is correct
84 Correct 40 ms 42080 KB Output is correct
85 Correct 143 ms 61276 KB Output is correct
86 Correct 394 ms 95984 KB Output is correct
87 Correct 365 ms 97508 KB Output is correct
88 Correct 339 ms 93044 KB Output is correct
89 Correct 359 ms 90712 KB Output is correct
90 Incorrect 313 ms 96592 KB Output isn't correct
91 Halted 0 ms 0 KB -