Submission #634584

# Submission time Handle Problem Language Result Execution time Memory
634584 2022-08-24T15:14:55 Z alvingogo Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
3000 ms 64488 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'+19))%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 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 3054 ms 26952 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 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 340 KB Output is correct
28 Correct 1 ms 212 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 0 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 0 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 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 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 340 KB Output is correct
28 Correct 1 ms 212 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 0 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 0 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 13 ms 660 KB Output is correct
42 Correct 15 ms 2132 KB Output is correct
43 Correct 14 ms 2116 KB Output is correct
44 Correct 15 ms 2176 KB Output is correct
45 Correct 15 ms 2072 KB Output is correct
46 Correct 17 ms 2260 KB Output is correct
47 Correct 698 ms 1424 KB Output is correct
48 Correct 855 ms 2044 KB Output is correct
49 Correct 737 ms 2352 KB Output is correct
50 Correct 583 ms 2244 KB Output is correct
51 Correct 1052 ms 1844 KB Output is correct
52 Correct 1079 ms 1936 KB Output is correct
53 Correct 15 ms 2132 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 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 340 KB Output is correct
28 Correct 1 ms 212 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 0 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 0 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 13 ms 660 KB Output is correct
42 Correct 15 ms 2132 KB Output is correct
43 Correct 14 ms 2116 KB Output is correct
44 Correct 15 ms 2176 KB Output is correct
45 Correct 15 ms 2072 KB Output is correct
46 Correct 17 ms 2260 KB Output is correct
47 Correct 698 ms 1424 KB Output is correct
48 Correct 855 ms 2044 KB Output is correct
49 Correct 737 ms 2352 KB Output is correct
50 Correct 583 ms 2244 KB Output is correct
51 Correct 1052 ms 1844 KB Output is correct
52 Correct 1079 ms 1936 KB Output is correct
53 Correct 15 ms 2132 KB Output is correct
54 Correct 87 ms 9380 KB Output is correct
55 Correct 1012 ms 8588 KB Output is correct
56 Incorrect 1829 ms 64488 KB Output isn't correct
57 Halted 0 ms 0 KB -
# 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Execution timed out 3054 ms 26952 KB Time limit exceeded
14 Halted 0 ms 0 KB -