답안 #568036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568036 2022-05-24T14:19:05 Z dantoh000 Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
879 ms 127916 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
const int INF = 1000000000000000000;
int n;
string s;
int a,b,c;
int dp[4505][4505];
int hsh[4505][4505];
int hsh2[4505][4505];
int nxt[4505][4505];
int mod = 1000000007, mod2 = 1000000009;
int H = 29, H2 = 31;
map<ii, vector<int> > groups;
main(){
    scanf("%lld",&n);
    cin >> s;
    scanf("%lld%lld%lld",&a,&b,&c);

    for (int i = 0; i < n; i++){
        hsh[i][i] = hsh2[i][i] = 0;
        for (int j = i+1; j <= n; j++){
            hsh[i][j] = (hsh[i][j-1]*H + (s[j-1]-'a'+1))%mod;
            hsh2[i][j] = (hsh2[i][j-1]*H2 + (s[j-1]-'a'+1))%mod2;
        }
    }

    for (int i = 1; i <= n/2; i++){
        groups.clear();
        for (int j = 0; j+i <= n; j++){
            groups[{hsh[j][j+i], hsh2[j][j+1]}].push_back(j);
        }
        for (auto it : groups){
            auto V = it.second;
            int cur = 0;
            for (int k = 0; k < V.size(); k++){
                int j = V[k];
                while (cur < V.size() && V[cur] < j+i) cur++;
                ///printf("%d, length %d --> %d\n",j,i,cur);
                if (cur == V.size()) nxt[i][j] = -1;
                else nxt[i][j] = V[cur];
            }
        }


    }

    for (int i = 0; i <= n; i++){
        dp[i][i] = 0;
        for (int j = i+1; j <= n; j++){
            dp[i][j] = INF;
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 0; j+i <= n; j++){
            dp[j][j+i] = min(dp[j][j+i],  min(dp[j+1][j+i], dp[j][j+i-1]) + a);
        }
        if (i <= n/2){
            for (int j = 0; j+i <= n; j++){
                int cur = j;
                int idx = 0;
                int ct = 0;
                int dpValue = dp[j][j+i];
                while (true){
                    ct++;
                    int L = j;
                    int R = cur + i;
                    dp[L][R] = min(dp[L][R], dpValue + b + ct*c + (R-L - i*ct)*a);
                    cur = nxt[i][cur];
                    if (cur == -1) break;
                }
            }
        }

    }

    printf("%lld\n",dp[0][n]);
}

Compilation message

copypaste3.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 | main(){
      | ^~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:37:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             for (int k = 0; k < V.size(); k++){
      |                             ~~^~~~~~~~~~
copypaste3.cpp:39:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |                 while (cur < V.size() && V[cur] < j+i) cur++;
      |                        ~~~~^~~~~~~~~~
copypaste3.cpp:41:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |                 if (cur == V.size()) nxt[i][j] = -1;
      |                     ~~~~^~~~~~~~~~~
copypaste3.cpp:62:21: warning: unused variable 'idx' [-Wunused-variable]
   62 |                 int idx = 0;
      |                     ^~~
copypaste3.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
copypaste3.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%lld%lld%lld",&a,&b,&c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 190 ms 75388 KB Output is correct
4 Correct 226 ms 85748 KB Output is correct
5 Correct 268 ms 97792 KB Output is correct
6 Correct 323 ms 111524 KB Output is correct
7 Correct 374 ms 127516 KB Output is correct
8 Correct 384 ms 127596 KB Output is correct
9 Correct 390 ms 127512 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 2 ms 1620 KB Output is correct
41 Correct 3 ms 3796 KB Output is correct
42 Correct 5 ms 3796 KB Output is correct
43 Correct 6 ms 3788 KB Output is correct
44 Correct 6 ms 3796 KB Output is correct
45 Correct 5 ms 3796 KB Output is correct
46 Correct 6 ms 3668 KB Output is correct
47 Correct 4 ms 3668 KB Output is correct
48 Correct 5 ms 3668 KB Output is correct
49 Correct 5 ms 3668 KB Output is correct
50 Correct 5 ms 3668 KB Output is correct
51 Correct 5 ms 3668 KB Output is correct
52 Correct 4 ms 3668 KB Output is correct
53 Correct 6 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 2 ms 1620 KB Output is correct
41 Correct 3 ms 3796 KB Output is correct
42 Correct 5 ms 3796 KB Output is correct
43 Correct 6 ms 3788 KB Output is correct
44 Correct 6 ms 3796 KB Output is correct
45 Correct 5 ms 3796 KB Output is correct
46 Correct 6 ms 3668 KB Output is correct
47 Correct 4 ms 3668 KB Output is correct
48 Correct 5 ms 3668 KB Output is correct
49 Correct 5 ms 3668 KB Output is correct
50 Correct 5 ms 3668 KB Output is correct
51 Correct 5 ms 3668 KB Output is correct
52 Correct 4 ms 3668 KB Output is correct
53 Correct 6 ms 3796 KB Output is correct
54 Correct 27 ms 9600 KB Output is correct
55 Correct 43 ms 29140 KB Output is correct
56 Correct 145 ms 29324 KB Output is correct
57 Correct 123 ms 29340 KB Output is correct
58 Correct 121 ms 29232 KB Output is correct
59 Correct 131 ms 29212 KB Output is correct
60 Correct 118 ms 29292 KB Output is correct
61 Correct 81 ms 29152 KB Output is correct
62 Correct 47 ms 29212 KB Output is correct
63 Correct 101 ms 29164 KB Output is correct
64 Correct 102 ms 29188 KB Output is correct
65 Correct 83 ms 29168 KB Output is correct
66 Correct 86 ms 29148 KB Output is correct
67 Correct 122 ms 29292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 190 ms 75388 KB Output is correct
14 Correct 226 ms 85748 KB Output is correct
15 Correct 268 ms 97792 KB Output is correct
16 Correct 323 ms 111524 KB Output is correct
17 Correct 374 ms 127516 KB Output is correct
18 Correct 384 ms 127596 KB Output is correct
19 Correct 390 ms 127512 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 724 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 1 ms 724 KB Output is correct
41 Correct 1 ms 724 KB Output is correct
42 Correct 1 ms 724 KB Output is correct
43 Correct 1 ms 724 KB Output is correct
44 Correct 1 ms 724 KB Output is correct
45 Correct 1 ms 724 KB Output is correct
46 Correct 1 ms 724 KB Output is correct
47 Correct 1 ms 724 KB Output is correct
48 Correct 1 ms 724 KB Output is correct
49 Correct 1 ms 724 KB Output is correct
50 Correct 1 ms 724 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 0 ms 468 KB Output is correct
56 Correct 1 ms 724 KB Output is correct
57 Correct 2 ms 1620 KB Output is correct
58 Correct 3 ms 3796 KB Output is correct
59 Correct 5 ms 3796 KB Output is correct
60 Correct 6 ms 3788 KB Output is correct
61 Correct 6 ms 3796 KB Output is correct
62 Correct 5 ms 3796 KB Output is correct
63 Correct 6 ms 3668 KB Output is correct
64 Correct 4 ms 3668 KB Output is correct
65 Correct 5 ms 3668 KB Output is correct
66 Correct 5 ms 3668 KB Output is correct
67 Correct 5 ms 3668 KB Output is correct
68 Correct 5 ms 3668 KB Output is correct
69 Correct 4 ms 3668 KB Output is correct
70 Correct 6 ms 3796 KB Output is correct
71 Correct 27 ms 9600 KB Output is correct
72 Correct 43 ms 29140 KB Output is correct
73 Correct 145 ms 29324 KB Output is correct
74 Correct 123 ms 29340 KB Output is correct
75 Correct 121 ms 29232 KB Output is correct
76 Correct 131 ms 29212 KB Output is correct
77 Correct 118 ms 29292 KB Output is correct
78 Correct 81 ms 29152 KB Output is correct
79 Correct 47 ms 29212 KB Output is correct
80 Correct 101 ms 29164 KB Output is correct
81 Correct 102 ms 29188 KB Output is correct
82 Correct 83 ms 29168 KB Output is correct
83 Correct 86 ms 29148 KB Output is correct
84 Correct 122 ms 29292 KB Output is correct
85 Correct 333 ms 59644 KB Output is correct
86 Correct 865 ms 127916 KB Output is correct
87 Correct 852 ms 127796 KB Output is correct
88 Correct 864 ms 127752 KB Output is correct
89 Correct 858 ms 127864 KB Output is correct
90 Correct 871 ms 127884 KB Output is correct
91 Correct 376 ms 127676 KB Output is correct
92 Correct 344 ms 127504 KB Output is correct
93 Correct 699 ms 127836 KB Output is correct
94 Correct 738 ms 127720 KB Output is correct
95 Correct 621 ms 127560 KB Output is correct
96 Correct 621 ms 127568 KB Output is correct
97 Correct 879 ms 127880 KB Output is correct