답안 #547042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547042 2022-04-09T09:31:26 Z ngrace Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
1048 ms 758384 KB
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <string>
using namespace std;
#define v vector
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
 
int main(){
    int N;
    cin>>N;
    string S;
    cin>>S;
    ll A,B,C;
    cin>>A>>B>>C;
    
    v<int> def(26, -1);
    v<v<int>> sub(1, v<int>(26, -1));
    int pairToInd[N][N+1];
    v<int> indToStarts[N*N+10];
    int subInd=1;
    for(int l=0; l<N; l++){
        int ind=0, child;
        for(int r=l; r<N; r++){
            child = S[r]-'a';
            if(sub[ind][child]==-1){
                sub.push_back(def);
                sub[ind][child] = subInd++;
            }
            ind=sub[ind][child];
            pairToInd[l][r-l+1] = ind;
            indToStarts[ind].push_back(l);
        }
    }
 
    v<v<int>> nextOccur(N,v<int>(N+1,N));
    for(int i=N-1; i>=0; i--){
        for(int s=1; s<=N-i; s++){
            int ind=pairToInd[i][s];
            v<int>::iterator next = lower_bound(indToStarts[ind].begin(), indToStarts[ind].end(), i+s);
            if(next!=indToStarts[ind].end()) nextOccur[i][s]=(*next);
        }
    }
 
    
    v<v<ll>> dp(N, v<ll>(N,1e17));
    for(int s=1; s<=N; s++){
        for(int l=N-1; l>=0; l--){
            dp[l][l]=A;
            if(s!=1 && l+s-1<N){
                dp[l][l+s-1] = min(dp[l][l+s-1], A+dp[l+1][l+s-1]);
                dp[l][l+s-1] = min(dp[l][l+s-1], dp[l][l+s-1-1]+A);
            }
            int num=2, nex=nextOccur[l][s];
            while(nex<N){
                int r=nex+s-1;
                dp[l][r] = min(dp[l][r], dp[l][l+s-1]+B+C*num+(r-l+1 - num*s)*A);
                dp[l][r] = min(dp[l][r], A+dp[l+1][r]);
                dp[l][r] = min(dp[l][r], dp[l][r-1]+A);
                nex=nextOccur[nex][s];
                num++;
            }
        }
    }
 
    cout<<dp[0][N-1]<<endl;
}
# 결과 실행 시간 메모리 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 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 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 429 ms 140812 KB Output is correct
4 Correct 543 ms 164300 KB Output is correct
5 Correct 712 ms 192092 KB Output is correct
6 Correct 866 ms 225008 KB Output is correct
7 Correct 1048 ms 262868 KB Output is correct
8 Correct 1038 ms 262976 KB Output is correct
9 Correct 1039 ms 263080 KB Output is correct
10 Correct 0 ms 284 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 340 KB Output is correct
17 Correct 0 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 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 1 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 Correct 0 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 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 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 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 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 1 ms 212 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 340 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 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 1 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 Correct 0 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 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 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 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 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 1 ms 212 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 1108 KB Output is correct
41 Correct 3 ms 2004 KB Output is correct
42 Correct 5 ms 5004 KB Output is correct
43 Correct 4 ms 5004 KB Output is correct
44 Correct 4 ms 5132 KB Output is correct
45 Correct 5 ms 5136 KB Output is correct
46 Correct 7 ms 5132 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 4 ms 3728 KB Output is correct
49 Correct 4 ms 4240 KB Output is correct
50 Correct 4 ms 4240 KB Output is correct
51 Correct 4 ms 3600 KB Output is correct
52 Correct 6 ms 3600 KB Output is correct
53 Correct 5 ms 5132 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 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 1 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 Correct 0 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 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 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 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 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 1 ms 212 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 1108 KB Output is correct
41 Correct 3 ms 2004 KB Output is correct
42 Correct 5 ms 5004 KB Output is correct
43 Correct 4 ms 5004 KB Output is correct
44 Correct 4 ms 5132 KB Output is correct
45 Correct 5 ms 5136 KB Output is correct
46 Correct 7 ms 5132 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 4 ms 3728 KB Output is correct
49 Correct 4 ms 4240 KB Output is correct
50 Correct 4 ms 4240 KB Output is correct
51 Correct 4 ms 3600 KB Output is correct
52 Correct 6 ms 3600 KB Output is correct
53 Correct 5 ms 5132 KB Output is correct
54 Correct 29 ms 24088 KB Output is correct
55 Correct 90 ms 42428 KB Output is correct
56 Correct 134 ms 120380 KB Output is correct
57 Correct 139 ms 120924 KB Output is correct
58 Correct 141 ms 121200 KB Output is correct
59 Correct 120 ms 121428 KB Output is correct
60 Correct 126 ms 121568 KB Output is correct
61 Correct 101 ms 74504 KB Output is correct
62 Correct 93 ms 43116 KB Output is correct
63 Correct 115 ms 101200 KB Output is correct
64 Correct 116 ms 101992 KB Output is correct
65 Correct 116 ms 80176 KB Output is correct
66 Correct 115 ms 80148 KB Output is correct
67 Correct 121 ms 121548 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 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 1 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 429 ms 140812 KB Output is correct
14 Correct 543 ms 164300 KB Output is correct
15 Correct 712 ms 192092 KB Output is correct
16 Correct 866 ms 225008 KB Output is correct
17 Correct 1048 ms 262868 KB Output is correct
18 Correct 1038 ms 262976 KB Output is correct
19 Correct 1039 ms 263080 KB Output is correct
20 Correct 0 ms 284 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 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 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 300 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 1108 KB Output is correct
58 Correct 3 ms 2004 KB Output is correct
59 Correct 5 ms 5004 KB Output is correct
60 Correct 4 ms 5004 KB Output is correct
61 Correct 4 ms 5132 KB Output is correct
62 Correct 5 ms 5136 KB Output is correct
63 Correct 7 ms 5132 KB Output is correct
64 Correct 3 ms 2772 KB Output is correct
65 Correct 4 ms 3728 KB Output is correct
66 Correct 4 ms 4240 KB Output is correct
67 Correct 4 ms 4240 KB Output is correct
68 Correct 4 ms 3600 KB Output is correct
69 Correct 6 ms 3600 KB Output is correct
70 Correct 5 ms 5132 KB Output is correct
71 Correct 29 ms 24088 KB Output is correct
72 Correct 90 ms 42428 KB Output is correct
73 Correct 134 ms 120380 KB Output is correct
74 Correct 139 ms 120924 KB Output is correct
75 Correct 141 ms 121200 KB Output is correct
76 Correct 120 ms 121428 KB Output is correct
77 Correct 126 ms 121568 KB Output is correct
78 Correct 101 ms 74504 KB Output is correct
79 Correct 93 ms 43116 KB Output is correct
80 Correct 115 ms 101200 KB Output is correct
81 Correct 116 ms 101992 KB Output is correct
82 Correct 116 ms 80176 KB Output is correct
83 Correct 115 ms 80148 KB Output is correct
84 Correct 121 ms 121548 KB Output is correct
85 Correct 353 ms 301444 KB Output is correct
86 Correct 844 ms 755100 KB Output is correct
87 Correct 840 ms 756532 KB Output is correct
88 Correct 822 ms 757672 KB Output is correct
89 Correct 793 ms 758220 KB Output is correct
90 Correct 796 ms 758344 KB Output is correct
91 Correct 683 ms 290732 KB Output is correct
92 Correct 830 ms 269220 KB Output is correct
93 Correct 726 ms 602088 KB Output is correct
94 Correct 772 ms 635048 KB Output is correct
95 Correct 932 ms 497512 KB Output is correct
96 Correct 907 ms 497448 KB Output is correct
97 Correct 794 ms 758384 KB Output is correct