답안 #634586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634586 2022-08-24T15:15:43 Z alvingogo Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
3000 ms 53992 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'+s[i-1]*2))%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;
}
# 결과 실행 시간 메모리 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 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 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 3053 ms 26840 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 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 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 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 1 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 1 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 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 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 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
# 결과 실행 시간 메모리 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 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 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 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 1 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 1 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 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 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 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 12 ms 644 KB Output is correct
42 Correct 16 ms 2120 KB Output is correct
43 Correct 15 ms 2132 KB Output is correct
44 Correct 15 ms 2148 KB Output is correct
45 Correct 14 ms 2132 KB Output is correct
46 Correct 15 ms 2120 KB Output is correct
47 Correct 700 ms 1420 KB Output is correct
48 Correct 882 ms 2020 KB Output is correct
49 Correct 701 ms 2292 KB Output is correct
50 Correct 587 ms 2324 KB Output is correct
51 Correct 1075 ms 1848 KB Output is correct
52 Correct 1068 ms 1872 KB Output is correct
53 Correct 14 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 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 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 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 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 1 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 1 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 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 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 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 12 ms 644 KB Output is correct
42 Correct 16 ms 2120 KB Output is correct
43 Correct 15 ms 2132 KB Output is correct
44 Correct 15 ms 2148 KB Output is correct
45 Correct 14 ms 2132 KB Output is correct
46 Correct 15 ms 2120 KB Output is correct
47 Correct 700 ms 1420 KB Output is correct
48 Correct 882 ms 2020 KB Output is correct
49 Correct 701 ms 2292 KB Output is correct
50 Correct 587 ms 2324 KB Output is correct
51 Correct 1075 ms 1848 KB Output is correct
52 Correct 1068 ms 1872 KB Output is correct
53 Correct 14 ms 2132 KB Output is correct
54 Correct 93 ms 9448 KB Output is correct
55 Correct 1027 ms 8348 KB Output is correct
56 Incorrect 1289 ms 53992 KB Output isn't correct
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 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 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 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Execution timed out 3053 ms 26840 KB Time limit exceeded
14 Halted 0 ms 0 KB -