답안 #1014305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014305 2024-07-04T16:19:21 Z Aiperiii Copy and Paste 3 (JOI22_copypaste3) C++14
20 / 100
1124 ms 83068 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];
        //cout<<h[i][i]<<" ";
        for(int j=i+1;j<n;j++){
            h[i][j]=h[i][j-1]*13+s[j];
            h[i][j]%=mod;
            //cout<<h[i][j]<<" ";
        }
        //cout<<"\n";
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i][j]=1e18;
        }
        dp[i][i]=a;
    }
    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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 514 ms 54384 KB Output is correct
4 Correct 611 ms 62244 KB Output is correct
5 Correct 833 ms 68860 KB Output is correct
6 Correct 865 ms 75664 KB Output is correct
7 Correct 1096 ms 83060 KB Output is correct
8 Correct 1124 ms 83068 KB Output is correct
9 Correct 1105 ms 83064 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 464 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 688 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 720 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 0 ms 604 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 0 ms 460 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 428 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 464 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 688 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 720 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 0 ms 604 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 0 ms 460 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 428 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 1 ms 1116 KB Output is correct
41 Correct 3 ms 2332 KB Output is correct
42 Correct 3 ms 2396 KB Output is correct
43 Correct 2 ms 2396 KB Output is correct
44 Correct 2 ms 2392 KB Output is correct
45 Correct 3 ms 2392 KB Output is correct
46 Correct 2 ms 2396 KB Output is correct
47 Correct 4 ms 2396 KB Output is correct
48 Correct 2 ms 2556 KB Output is correct
49 Correct 3 ms 2392 KB Output is correct
50 Correct 2 ms 2396 KB Output is correct
51 Correct 3 ms 2548 KB Output is correct
52 Correct 4 ms 2396 KB Output is correct
53 Incorrect 2 ms 2396 KB Output isn't correct
54 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 464 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 688 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 720 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 0 ms 604 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 0 ms 460 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 428 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 1 ms 1116 KB Output is correct
41 Correct 3 ms 2332 KB Output is correct
42 Correct 3 ms 2396 KB Output is correct
43 Correct 2 ms 2396 KB Output is correct
44 Correct 2 ms 2392 KB Output is correct
45 Correct 3 ms 2392 KB Output is correct
46 Correct 2 ms 2396 KB Output is correct
47 Correct 4 ms 2396 KB Output is correct
48 Correct 2 ms 2556 KB Output is correct
49 Correct 3 ms 2392 KB Output is correct
50 Correct 2 ms 2396 KB Output is correct
51 Correct 3 ms 2548 KB Output is correct
52 Correct 4 ms 2396 KB Output is correct
53 Incorrect 2 ms 2396 KB Output isn't correct
54 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 514 ms 54384 KB Output is correct
14 Correct 611 ms 62244 KB Output is correct
15 Correct 833 ms 68860 KB Output is correct
16 Correct 865 ms 75664 KB Output is correct
17 Correct 1096 ms 83060 KB Output is correct
18 Correct 1124 ms 83068 KB Output is correct
19 Correct 1105 ms 83064 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 600 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 0 ms 464 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 604 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 0 ms 604 KB Output is correct
41 Correct 0 ms 604 KB Output is correct
42 Correct 0 ms 604 KB Output is correct
43 Correct 0 ms 688 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 720 KB Output is correct
46 Correct 0 ms 604 KB Output is correct
47 Correct 0 ms 604 KB Output is correct
48 Correct 1 ms 860 KB Output is correct
49 Correct 0 ms 604 KB Output is correct
50 Correct 0 ms 604 KB Output is correct
51 Correct 0 ms 604 KB Output is correct
52 Correct 0 ms 460 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 428 KB Output is correct
56 Correct 0 ms 604 KB Output is correct
57 Correct 1 ms 1116 KB Output is correct
58 Correct 3 ms 2332 KB Output is correct
59 Correct 3 ms 2396 KB Output is correct
60 Correct 2 ms 2396 KB Output is correct
61 Correct 2 ms 2392 KB Output is correct
62 Correct 3 ms 2392 KB Output is correct
63 Correct 2 ms 2396 KB Output is correct
64 Correct 4 ms 2396 KB Output is correct
65 Correct 2 ms 2556 KB Output is correct
66 Correct 3 ms 2392 KB Output is correct
67 Correct 2 ms 2396 KB Output is correct
68 Correct 3 ms 2548 KB Output is correct
69 Correct 4 ms 2396 KB Output is correct
70 Incorrect 2 ms 2396 KB Output isn't correct
71 Halted 0 ms 0 KB -