Submission #634572

# Submission time Handle Problem Language Result Execution time Memory
634572 2022-08-24T15:07:23 Z alvingogo Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
3000 ms 67808 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
#define int long long
using namespace std;

string s;
int n,a,b,c;
const int bs=53,mod=1e9+7;
vector<int> pre,fac;
vector<vector<int> > g;
map<int,int> dp;
int inv(int x){
    return x==1?1:(inv(mod%x)*(mod-mod/x)%mod);
}
void init(){
    pre.resize(n+5);
    fac.resize(n+5);
    fac[0]=1;
    pre[0]=0;
    for(int i=1;i<=n;i++){
        fac[i]=fac[i-1]*bs%mod;
        pre[i]=(pre[i-1]+fac[i]*(s[i-1]-'a'+18))%mod;
    }
}
int ha(int l,int r){
    l++;
    r++;
    return (pre[r]-pre[l-1]+mod)*inv(fac[l])%mod;
}
int get(int l,int r){
    if(dp.find(g[l][r])!=dp.end()){
        return dp[g[l][r]];
    }
    int ans=(r-l+1)*a;
    map<int,pair<int,pair<int,int> > > m;
    for(int i=l;i<=r;i++){
        for(int j=1;i+j-1<=r;j++){
            auto z=g[i][i+j-1];
            if(m.find(z)!=m.end()){
                if(m[z].sc.sc<i){
                    m[z].fs++;
                    m[z].sc={i,i+j-1};
                }
            }
            else{
                m[z]={1,{i,i+j-1}};
            }
        }   
    }
    for(auto h:m){
        if(h.sc.fs<=1){
            continue;
        }
        int p=get(h.sc.sc.fs,h.sc.sc.sc);
        ans=min(ans,p+a*(r-l+1-h.sc.fs*(h.sc.sc.sc-h.sc.sc.fs+1))+b+c*h.sc.fs);
    }
    return dp[g[l][r]]=ans;
}
signed main(){
    AquA;
    cin >> n >> s >> a >> b >> c;
    init();
    g.resize(n,vector<int>(n));
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            g[i][j]=ha(i,j);
        }
    }
    cout << get(0,n-1) << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 3066 ms 27076 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 284 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 284 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 15 ms 596 KB Output is correct
42 Correct 17 ms 2132 KB Output is correct
43 Correct 17 ms 2136 KB Output is correct
44 Correct 20 ms 2164 KB Output is correct
45 Correct 17 ms 2072 KB Output is correct
46 Correct 16 ms 2176 KB Output is correct
47 Correct 754 ms 1468 KB Output is correct
48 Correct 884 ms 2088 KB Output is correct
49 Correct 684 ms 2244 KB Output is correct
50 Correct 557 ms 2232 KB Output is correct
51 Correct 1044 ms 1968 KB Output is correct
52 Correct 1055 ms 2032 KB Output is correct
53 Correct 14 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 284 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 15 ms 596 KB Output is correct
42 Correct 17 ms 2132 KB Output is correct
43 Correct 17 ms 2136 KB Output is correct
44 Correct 20 ms 2164 KB Output is correct
45 Correct 17 ms 2072 KB Output is correct
46 Correct 16 ms 2176 KB Output is correct
47 Correct 754 ms 1468 KB Output is correct
48 Correct 884 ms 2088 KB Output is correct
49 Correct 684 ms 2244 KB Output is correct
50 Correct 557 ms 2232 KB Output is correct
51 Correct 1044 ms 1968 KB Output is correct
52 Correct 1055 ms 2032 KB Output is correct
53 Correct 14 ms 2132 KB Output is correct
54 Correct 100 ms 10120 KB Output is correct
55 Correct 1014 ms 8456 KB Output is correct
56 Incorrect 1398 ms 67808 KB Output isn't correct
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Execution timed out 3066 ms 27076 KB Time limit exceeded
14 Halted 0 ms 0 KB -