Submission #634569

# Submission time Handle Problem Language Result Execution time Memory
634569 2022-08-24T15:05:04 Z alvingogo Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
3000 ms 56596 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=47,mod=1e9+9;
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'+10))%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 0 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 212 KB Output is correct
6 Correct 1 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 0 ms 212 KB Output is correct
3 Execution timed out 3095 ms 26836 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 0 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 212 KB Output is correct
6 Correct 1 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 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 1 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 0 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 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 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 0 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 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 1 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 0 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 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 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 2 ms 596 KB Output is correct
41 Correct 11 ms 640 KB Output is correct
42 Correct 14 ms 2052 KB Output is correct
43 Correct 13 ms 2052 KB Output is correct
44 Correct 13 ms 2132 KB Output is correct
45 Correct 15 ms 2132 KB Output is correct
46 Correct 13 ms 2132 KB Output is correct
47 Correct 706 ms 1312 KB Output is correct
48 Correct 871 ms 2100 KB Output is correct
49 Correct 681 ms 2248 KB Output is correct
50 Correct 569 ms 2236 KB Output is correct
51 Correct 1018 ms 1740 KB Output is correct
52 Correct 1262 ms 1892 KB Output is correct
53 Correct 15 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 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 1 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 0 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 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 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 2 ms 596 KB Output is correct
41 Correct 11 ms 640 KB Output is correct
42 Correct 14 ms 2052 KB Output is correct
43 Correct 13 ms 2052 KB Output is correct
44 Correct 13 ms 2132 KB Output is correct
45 Correct 15 ms 2132 KB Output is correct
46 Correct 13 ms 2132 KB Output is correct
47 Correct 706 ms 1312 KB Output is correct
48 Correct 871 ms 2100 KB Output is correct
49 Correct 681 ms 2248 KB Output is correct
50 Correct 569 ms 2236 KB Output is correct
51 Correct 1018 ms 1740 KB Output is correct
52 Correct 1262 ms 1892 KB Output is correct
53 Correct 15 ms 2132 KB Output is correct
54 Correct 96 ms 9492 KB Output is correct
55 Correct 1047 ms 8404 KB Output is correct
56 Incorrect 1395 ms 56596 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 0 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 212 KB Output is correct
6 Correct 1 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 0 ms 212 KB Output is correct
13 Execution timed out 3095 ms 26836 KB Time limit exceeded
14 Halted 0 ms 0 KB -