답안 #1014316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014316 2024-07-04T16:25:45 Z Aiperiii Copy and Paste 3 (JOI22_copypaste3) C++14
62 / 100
1115 ms 70740 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;
            dp[i][j]=1e18;
            //cout<<h[i][j]<<" ";
        }
        dp[i][i]=a;
        //cout<<"\n";
    }
    
    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
*/



# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 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 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 499 ms 46660 KB Output is correct
4 Correct 612 ms 55132 KB Output is correct
5 Correct 748 ms 57008 KB Output is correct
6 Correct 909 ms 62344 KB Output is correct
7 Correct 1115 ms 69360 KB Output is correct
8 Correct 1010 ms 70736 KB Output is correct
9 Correct 1061 ms 70740 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 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 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 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 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 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 0 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 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 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 6492 KB Output is correct
30 Correct 1 ms 6488 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2396 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 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 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 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 0 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 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 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 6492 KB Output is correct
30 Correct 1 ms 6488 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2396 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 1 ms 6488 KB Output is correct
41 Correct 3 ms 10588 KB Output is correct
42 Correct 2 ms 10588 KB Output is correct
43 Correct 2 ms 10588 KB Output is correct
44 Correct 2 ms 10588 KB Output is correct
45 Correct 2 ms 10588 KB Output is correct
46 Correct 2 ms 10784 KB Output is correct
47 Correct 3 ms 10588 KB Output is correct
48 Correct 3 ms 10588 KB Output is correct
49 Correct 3 ms 10584 KB Output is correct
50 Correct 3 ms 10584 KB Output is correct
51 Correct 3 ms 10588 KB Output is correct
52 Correct 3 ms 10588 KB Output is correct
53 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 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 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 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 0 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 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 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 6492 KB Output is correct
30 Correct 1 ms 6488 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2396 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 1 ms 6488 KB Output is correct
41 Correct 3 ms 10588 KB Output is correct
42 Correct 2 ms 10588 KB Output is correct
43 Correct 2 ms 10588 KB Output is correct
44 Correct 2 ms 10588 KB Output is correct
45 Correct 2 ms 10588 KB Output is correct
46 Correct 2 ms 10784 KB Output is correct
47 Correct 3 ms 10588 KB Output is correct
48 Correct 3 ms 10588 KB Output is correct
49 Correct 3 ms 10584 KB Output is correct
50 Correct 3 ms 10584 KB Output is correct
51 Correct 3 ms 10588 KB Output is correct
52 Correct 3 ms 10588 KB Output is correct
53 Correct 2 ms 10588 KB Output is correct
54 Correct 10 ms 22876 KB Output is correct
55 Correct 83 ms 32348 KB Output is correct
56 Correct 56 ms 36696 KB Output is correct
57 Correct 42 ms 36700 KB Output is correct
58 Correct 43 ms 35160 KB Output is correct
59 Correct 39 ms 36700 KB Output is correct
60 Correct 44 ms 35160 KB Output is correct
61 Correct 71 ms 35164 KB Output is correct
62 Correct 80 ms 35164 KB Output is correct
63 Correct 55 ms 36852 KB Output is correct
64 Correct 57 ms 32344 KB Output is correct
65 Correct 74 ms 31052 KB Output is correct
66 Correct 83 ms 35164 KB Output is correct
67 Correct 39 ms 32344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 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 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 499 ms 46660 KB Output is correct
14 Correct 612 ms 55132 KB Output is correct
15 Correct 748 ms 57008 KB Output is correct
16 Correct 909 ms 62344 KB Output is correct
17 Correct 1115 ms 69360 KB Output is correct
18 Correct 1010 ms 70736 KB Output is correct
19 Correct 1061 ms 70740 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 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 1 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 0 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 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 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 6492 KB Output is correct
47 Correct 1 ms 6488 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 0 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 0 ms 2396 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 1 ms 6488 KB Output is correct
58 Correct 3 ms 10588 KB Output is correct
59 Correct 2 ms 10588 KB Output is correct
60 Correct 2 ms 10588 KB Output is correct
61 Correct 2 ms 10588 KB Output is correct
62 Correct 2 ms 10588 KB Output is correct
63 Correct 2 ms 10784 KB Output is correct
64 Correct 3 ms 10588 KB Output is correct
65 Correct 3 ms 10588 KB Output is correct
66 Correct 3 ms 10584 KB Output is correct
67 Correct 3 ms 10584 KB Output is correct
68 Correct 3 ms 10588 KB Output is correct
69 Correct 3 ms 10588 KB Output is correct
70 Correct 2 ms 10588 KB Output is correct
71 Correct 10 ms 22876 KB Output is correct
72 Correct 83 ms 32348 KB Output is correct
73 Correct 56 ms 36696 KB Output is correct
74 Correct 42 ms 36700 KB Output is correct
75 Correct 43 ms 35160 KB Output is correct
76 Correct 39 ms 36700 KB Output is correct
77 Correct 44 ms 35160 KB Output is correct
78 Correct 71 ms 35164 KB Output is correct
79 Correct 80 ms 35164 KB Output is correct
80 Correct 55 ms 36852 KB Output is correct
81 Correct 57 ms 32344 KB Output is correct
82 Correct 74 ms 31052 KB Output is correct
83 Correct 83 ms 35164 KB Output is correct
84 Correct 39 ms 32344 KB Output is correct
85 Correct 132 ms 42732 KB Output is correct
86 Correct 357 ms 69208 KB Output is correct
87 Correct 324 ms 69208 KB Output is correct
88 Correct 313 ms 68952 KB Output is correct
89 Correct 299 ms 69456 KB Output is correct
90 Incorrect 279 ms 69456 KB Output isn't correct
91 Halted 0 ms 0 KB -