답안 #992027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992027 2024-06-03T15:40:07 Z snpmrnhlol Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
225 ms 98396 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 25e2;
const ll inf = 1e18;
char v[N];
int lcp[N][N];
int nxt[N][N];
ll dp[N][N];
int main(){
    int n;
    cin>>n;
    for(int i = 0;i < n;i++){
        cin>>v[i];
    }
    int a,b,c;
    cin>>a>>b>>c;
    for(int i = n - 1;i >= 0;i--){
        for(int j = n - 1;j >=0;j--){
            if(v[i] == v[j]){
                lcp[i][j] = 1 + ((i == n - 1 || j == n - 1)?0:lcp[i + 1][j + 1]);
            }else lcp[i][j] = 0;
            nxt[i][j] = n;
            dp[i][j] = inf;
        }
    }
    for(int i = n - 1;i >= 0;i--){
        int k = i;
        int j = i + 1;
        while(k < n){
            j = max(j,k + 1);
            while(j < n && lcp[i][j] <= k - i){
                j++;
            }
            nxt[i][k] = j;
            k++;
        }
    }
    for(int i = n - 1;i >= 0;i--){
        for(int j = i;j < n;j++){
            if(i == j)dp[i][j] = min(dp[i][j],(ll)a);
            else dp[i][j] = min(dp[i][j],min(dp[i + 1][j],dp[i][j - 1]) + (ll)a);
            ///propogate
            int k = j;
            int cnt = 0;
            int length = j - i + 1;
            while(k < n){
                cnt++;
                //cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j] + b + c*cnt + a*(k - i + 1 - length*cnt)<<' '<<(k - i + 1 - length*cnt)<<'\n';
                dp[i][k] = min(dp[i][k],dp[i][j] + b + 1ll*c*cnt + 1ll*a*(k - i + 1 - length*cnt));
                k = nxt[k - length + 1][k] + length - 1;
            }
            //cout<<dp[i][j]<<' '<<nxt[i][j]<<' '<<i<<' '<<j<<'\n';
        }
    }
    cout<<dp[0][n - 1];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 109 ms 78568 KB Output is correct
4 Correct 122 ms 84736 KB Output is correct
5 Correct 145 ms 88780 KB Output is correct
6 Correct 187 ms 94812 KB Output is correct
7 Correct 202 ms 98300 KB Output is correct
8 Correct 225 ms 98140 KB Output is correct
9 Correct 210 ms 98140 KB Output is correct
10 Correct 1 ms 4444 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 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6588 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6608 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6592 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 6744 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 6492 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 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6588 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6608 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6592 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 6744 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 6492 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 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 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 10588 KB Output is correct
41 Correct 2 ms 12732 KB Output is correct
42 Correct 2 ms 12744 KB Output is correct
43 Correct 2 ms 12636 KB Output is correct
44 Correct 2 ms 12636 KB Output is correct
45 Correct 2 ms 12804 KB Output is correct
46 Correct 2 ms 12636 KB Output is correct
47 Correct 2 ms 12636 KB Output is correct
48 Correct 2 ms 12636 KB Output is correct
49 Correct 2 ms 12636 KB Output is correct
50 Correct 2 ms 12636 KB Output is correct
51 Correct 2 ms 12636 KB Output is correct
52 Correct 2 ms 12636 KB Output is correct
53 Correct 1 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6588 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6608 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6592 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 6744 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 6492 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 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 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 10588 KB Output is correct
41 Correct 2 ms 12732 KB Output is correct
42 Correct 2 ms 12744 KB Output is correct
43 Correct 2 ms 12636 KB Output is correct
44 Correct 2 ms 12636 KB Output is correct
45 Correct 2 ms 12804 KB Output is correct
46 Correct 2 ms 12636 KB Output is correct
47 Correct 2 ms 12636 KB Output is correct
48 Correct 2 ms 12636 KB Output is correct
49 Correct 2 ms 12636 KB Output is correct
50 Correct 2 ms 12636 KB Output is correct
51 Correct 2 ms 12636 KB Output is correct
52 Correct 2 ms 12636 KB Output is correct
53 Correct 1 ms 12636 KB Output is correct
54 Correct 4 ms 22876 KB Output is correct
55 Correct 28 ms 45660 KB Output is correct
56 Correct 12 ms 45660 KB Output is correct
57 Correct 11 ms 45660 KB Output is correct
58 Correct 9 ms 45660 KB Output is correct
59 Correct 9 ms 45660 KB Output is correct
60 Correct 9 ms 45660 KB Output is correct
61 Correct 11 ms 45564 KB Output is correct
62 Correct 23 ms 45660 KB Output is correct
63 Correct 10 ms 45660 KB Output is correct
64 Correct 11 ms 45696 KB Output is correct
65 Correct 16 ms 45704 KB Output is correct
66 Correct 16 ms 45660 KB Output is correct
67 Correct 9 ms 45528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 109 ms 78568 KB Output is correct
14 Correct 122 ms 84736 KB Output is correct
15 Correct 145 ms 88780 KB Output is correct
16 Correct 187 ms 94812 KB Output is correct
17 Correct 202 ms 98300 KB Output is correct
18 Correct 225 ms 98140 KB Output is correct
19 Correct 210 ms 98140 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 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 4444 KB Output is correct
28 Correct 1 ms 6588 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 6608 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 6592 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 6744 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 6492 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 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 1 ms 10588 KB Output is correct
58 Correct 2 ms 12732 KB Output is correct
59 Correct 2 ms 12744 KB Output is correct
60 Correct 2 ms 12636 KB Output is correct
61 Correct 2 ms 12636 KB Output is correct
62 Correct 2 ms 12804 KB Output is correct
63 Correct 2 ms 12636 KB Output is correct
64 Correct 2 ms 12636 KB Output is correct
65 Correct 2 ms 12636 KB Output is correct
66 Correct 2 ms 12636 KB Output is correct
67 Correct 2 ms 12636 KB Output is correct
68 Correct 2 ms 12636 KB Output is correct
69 Correct 2 ms 12636 KB Output is correct
70 Correct 1 ms 12636 KB Output is correct
71 Correct 4 ms 22876 KB Output is correct
72 Correct 28 ms 45660 KB Output is correct
73 Correct 12 ms 45660 KB Output is correct
74 Correct 11 ms 45660 KB Output is correct
75 Correct 9 ms 45660 KB Output is correct
76 Correct 9 ms 45660 KB Output is correct
77 Correct 9 ms 45660 KB Output is correct
78 Correct 11 ms 45564 KB Output is correct
79 Correct 23 ms 45660 KB Output is correct
80 Correct 10 ms 45660 KB Output is correct
81 Correct 11 ms 45696 KB Output is correct
82 Correct 16 ms 45704 KB Output is correct
83 Correct 16 ms 45660 KB Output is correct
84 Correct 9 ms 45528 KB Output is correct
85 Correct 26 ms 68188 KB Output is correct
86 Correct 63 ms 98264 KB Output is correct
87 Correct 48 ms 98052 KB Output is correct
88 Correct 42 ms 98140 KB Output is correct
89 Correct 38 ms 98136 KB Output is correct
90 Correct 38 ms 98140 KB Output is correct
91 Correct 85 ms 98140 KB Output is correct
92 Correct 119 ms 98140 KB Output is correct
93 Correct 47 ms 98140 KB Output is correct
94 Correct 52 ms 98140 KB Output is correct
95 Correct 97 ms 98140 KB Output is correct
96 Correct 96 ms 98140 KB Output is correct
97 Correct 41 ms 98396 KB Output is correct