답안 #634709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634709 2022-08-24T17:38:30 Z alvingogo Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
1868 ms 220888 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;

signed main(){
    AquA;
    string s;
    int n,a,b,c;
    const int bs=37,mod=1e9+7;
    cin >> n >> s >> a >> b >> c;
    vector<vector<int> > g(n,vector<int>(n));
    vector<int> p;
    for(int i=0;i<n;i++){
        int k=0;
        for(int j=i;j<n;j++){
            k*=bs;
            k+=s[j];
            k%=mod;
            g[i][j]=k;
            p.push_back(g[i][j]);
        }
    }
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            g[i][j]=lower_bound(p.begin(),p.end(),g[i][j])-p.begin();
        }
    }
    vector<vector<int> > from(n,vector<int>(n,-1));
    vector<int> m(n*n,-1);
    for(int l=1;l<=n;l++){
        for(int j=0;j+l-1<n;j++){
            from[j][j+l-1]=m[g[j][j+l-1]];
            if(j-l+1>=0){
                m[g[j-l+1][j]]=j-l+1;
            }
        }
        for(int j=0;j+l-1<n;j++){
            if(j-l+1>=0){
                m[g[j-l+1][j]]=-1;
            }
        }
    }
    vector<vector<int> > zzz(n,vector<int>(n,1e18));
    for(int r=0;r<n;r++){
        for(int l=r;l>=0;l--){
            if(l==r){
                zzz[l][r]=a;
            }
            else{
                zzz[l][r]=min(zzz[l][r],min(zzz[l+1][r]+a,zzz[l][r-1]+a));
            }
            int j=from[l][r],t=2;
            for(;j>=0;j=from[j][j+r-l]){
                zzz[j][r]=min(zzz[j][r],zzz[l][r]+c*t+b+a*(r-j+1-(r-l+1)*t));
                t++;
            }
            //cout << l << " " << r << " " << zzz[l][r] << "\n";
        }
    }
    cout << zzz[0][n-1] << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 1 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 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 604 ms 118356 KB Output is correct
4 Correct 726 ms 138332 KB Output is correct
5 Correct 908 ms 161644 KB Output is correct
6 Correct 1029 ms 188720 KB Output is correct
7 Correct 1306 ms 220884 KB Output is correct
8 Correct 1428 ms 220888 KB Output is correct
9 Correct 1179 ms 220760 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 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 1 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 1 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 1 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 1 ms 212 KB Output is correct
11 Correct 1 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 1 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 232 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 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 1 ms 340 KB Output is correct
31 Correct 0 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 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 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 1 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 1 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 232 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 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 1 ms 340 KB Output is correct
31 Correct 0 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 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 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 3 ms 1744 KB Output is correct
42 Correct 5 ms 1744 KB Output is correct
43 Correct 5 ms 1744 KB Output is correct
44 Correct 5 ms 1744 KB Output is correct
45 Correct 5 ms 1744 KB Output is correct
46 Correct 5 ms 1744 KB Output is correct
47 Correct 5 ms 1744 KB Output is correct
48 Correct 4 ms 1744 KB Output is correct
49 Correct 4 ms 1744 KB Output is correct
50 Correct 4 ms 1744 KB Output is correct
51 Correct 5 ms 1744 KB Output is correct
52 Correct 5 ms 1704 KB Output is correct
53 Correct 4 ms 1744 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 1 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 1 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 232 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 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 1 ms 340 KB Output is correct
31 Correct 0 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 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 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 3 ms 1744 KB Output is correct
42 Correct 5 ms 1744 KB Output is correct
43 Correct 5 ms 1744 KB Output is correct
44 Correct 5 ms 1744 KB Output is correct
45 Correct 5 ms 1744 KB Output is correct
46 Correct 5 ms 1744 KB Output is correct
47 Correct 5 ms 1744 KB Output is correct
48 Correct 4 ms 1744 KB Output is correct
49 Correct 4 ms 1744 KB Output is correct
50 Correct 4 ms 1744 KB Output is correct
51 Correct 5 ms 1744 KB Output is correct
52 Correct 5 ms 1704 KB Output is correct
53 Correct 4 ms 1744 KB Output is correct
54 Correct 24 ms 7376 KB Output is correct
55 Correct 111 ms 35652 KB Output is correct
56 Correct 180 ms 35672 KB Output is correct
57 Correct 161 ms 35736 KB Output is correct
58 Correct 156 ms 35652 KB Output is correct
59 Correct 154 ms 35644 KB Output is correct
60 Correct 151 ms 35552 KB Output is correct
61 Correct 151 ms 35656 KB Output is correct
62 Correct 128 ms 35672 KB Output is correct
63 Correct 155 ms 35660 KB Output is correct
64 Correct 153 ms 35616 KB Output is correct
65 Correct 173 ms 35780 KB Output is correct
66 Correct 178 ms 35652 KB Output is correct
67 Correct 152 ms 35656 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 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 604 ms 118356 KB Output is correct
14 Correct 726 ms 138332 KB Output is correct
15 Correct 908 ms 161644 KB Output is correct
16 Correct 1029 ms 188720 KB Output is correct
17 Correct 1306 ms 220884 KB Output is correct
18 Correct 1428 ms 220888 KB Output is correct
19 Correct 1179 ms 220760 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 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 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 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 232 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 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 1 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 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 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 3 ms 1744 KB Output is correct
59 Correct 5 ms 1744 KB Output is correct
60 Correct 5 ms 1744 KB Output is correct
61 Correct 5 ms 1744 KB Output is correct
62 Correct 5 ms 1744 KB Output is correct
63 Correct 5 ms 1744 KB Output is correct
64 Correct 5 ms 1744 KB Output is correct
65 Correct 4 ms 1744 KB Output is correct
66 Correct 4 ms 1744 KB Output is correct
67 Correct 4 ms 1744 KB Output is correct
68 Correct 5 ms 1744 KB Output is correct
69 Correct 5 ms 1704 KB Output is correct
70 Correct 4 ms 1744 KB Output is correct
71 Correct 24 ms 7376 KB Output is correct
72 Correct 111 ms 35652 KB Output is correct
73 Correct 180 ms 35672 KB Output is correct
74 Correct 161 ms 35736 KB Output is correct
75 Correct 156 ms 35652 KB Output is correct
76 Correct 154 ms 35644 KB Output is correct
77 Correct 151 ms 35552 KB Output is correct
78 Correct 151 ms 35656 KB Output is correct
79 Correct 128 ms 35672 KB Output is correct
80 Correct 155 ms 35660 KB Output is correct
81 Correct 153 ms 35616 KB Output is correct
82 Correct 173 ms 35780 KB Output is correct
83 Correct 178 ms 35652 KB Output is correct
84 Correct 152 ms 35656 KB Output is correct
85 Correct 548 ms 88488 KB Output is correct
86 Correct 1707 ms 220692 KB Output is correct
87 Correct 1652 ms 220844 KB Output is correct
88 Correct 1748 ms 220760 KB Output is correct
89 Correct 1743 ms 220756 KB Output is correct
90 Correct 1661 ms 220820 KB Output is correct
91 Correct 1295 ms 220744 KB Output is correct
92 Correct 1331 ms 220756 KB Output is correct
93 Correct 1868 ms 220824 KB Output is correct
94 Correct 1768 ms 220828 KB Output is correct
95 Correct 1816 ms 220836 KB Output is correct
96 Correct 1806 ms 220820 KB Output is correct
97 Correct 1707 ms 220816 KB Output is correct