답안 #568034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568034 2022-05-24T14:16:14 Z dantoh000 Copy and Paste 3 (JOI22_copypaste3) C++14
62 / 100
804 ms 93268 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
int n;
string s;
int a,b,c;
int dp[4505][4505];
int hsh[4505][4505];
int nxt[4505][4505];
int mod = 1000000007;
int GRP[4505];
int H = 29;
map<int, 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] = 0;
        for (int j = i+1; j <= n; j++){
            hsh[i][j] = (hsh[i][j-1]*H + (s[j-1]-'a'+1))%mod;
        }
    }

    for (int i = 1; i <= n/2; i++){
        groups.clear();
        for (int j = 0; j+i <= n; j++){
            groups[hsh[j][j+i]].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:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   15 | main(){
      | ^~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:35: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]
   35 |             for (int k = 0; k < V.size(); k++){
      |                             ~~^~~~~~~~~~
copypaste3.cpp:37: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]
   37 |                 while (cur < V.size() && V[cur] < j+i) cur++;
      |                        ~~~~^~~~~~~~~~
copypaste3.cpp:39: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]
   39 |                 if (cur == V.size()) nxt[i][j] = -1;
      |                     ~~~~^~~~~~~~~~~
copypaste3.cpp:60:21: warning: unused variable 'idx' [-Wunused-variable]
   60 |                 int idx = 0;
      |                     ^~~
copypaste3.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
copypaste3.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%lld%lld%lld",&a,&b,&c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 1 ms 340 KB Output is correct
3 Correct 177 ms 54860 KB Output is correct
4 Correct 215 ms 62500 KB Output is correct
5 Correct 251 ms 71324 KB Output is correct
6 Correct 289 ms 81228 KB Output is correct
7 Correct 386 ms 92880 KB Output is correct
8 Correct 355 ms 92984 KB Output is correct
9 Correct 347 ms 92988 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 424 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 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 308 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 424 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 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 308 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 2 ms 1236 KB Output is correct
41 Correct 2 ms 2772 KB Output is correct
42 Correct 6 ms 2772 KB Output is correct
43 Correct 5 ms 2740 KB Output is correct
44 Correct 5 ms 2772 KB Output is correct
45 Correct 5 ms 2772 KB Output is correct
46 Correct 6 ms 2740 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 4 ms 2772 KB Output is correct
49 Correct 4 ms 2772 KB Output is correct
50 Correct 4 ms 2772 KB Output is correct
51 Correct 3 ms 2772 KB Output is correct
52 Correct 4 ms 2772 KB Output is correct
53 Correct 6 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 424 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 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 308 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 2 ms 1236 KB Output is correct
41 Correct 2 ms 2772 KB Output is correct
42 Correct 6 ms 2772 KB Output is correct
43 Correct 5 ms 2740 KB Output is correct
44 Correct 5 ms 2772 KB Output is correct
45 Correct 5 ms 2772 KB Output is correct
46 Correct 6 ms 2740 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 4 ms 2772 KB Output is correct
49 Correct 4 ms 2772 KB Output is correct
50 Correct 4 ms 2772 KB Output is correct
51 Correct 3 ms 2772 KB Output is correct
52 Correct 4 ms 2772 KB Output is correct
53 Correct 6 ms 2772 KB Output is correct
54 Correct 21 ms 7036 KB Output is correct
55 Correct 34 ms 21276 KB Output is correct
56 Correct 107 ms 21260 KB Output is correct
57 Correct 112 ms 21292 KB Output is correct
58 Correct 141 ms 21332 KB Output is correct
59 Correct 104 ms 21312 KB Output is correct
60 Correct 115 ms 21324 KB Output is correct
61 Correct 69 ms 21252 KB Output is correct
62 Correct 37 ms 21252 KB Output is correct
63 Correct 100 ms 21276 KB Output is correct
64 Correct 93 ms 21328 KB Output is correct
65 Correct 68 ms 21308 KB Output is correct
66 Correct 68 ms 21240 KB Output is correct
67 Correct 98 ms 21448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 340 KB Output is correct
13 Correct 177 ms 54860 KB Output is correct
14 Correct 215 ms 62500 KB Output is correct
15 Correct 251 ms 71324 KB Output is correct
16 Correct 289 ms 81228 KB Output is correct
17 Correct 386 ms 92880 KB Output is correct
18 Correct 355 ms 92984 KB Output is correct
19 Correct 347 ms 92988 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 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 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 436 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 424 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 1 ms 596 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 1 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 308 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 2 ms 1236 KB Output is correct
58 Correct 2 ms 2772 KB Output is correct
59 Correct 6 ms 2772 KB Output is correct
60 Correct 5 ms 2740 KB Output is correct
61 Correct 5 ms 2772 KB Output is correct
62 Correct 5 ms 2772 KB Output is correct
63 Correct 6 ms 2740 KB Output is correct
64 Correct 3 ms 2772 KB Output is correct
65 Correct 4 ms 2772 KB Output is correct
66 Correct 4 ms 2772 KB Output is correct
67 Correct 4 ms 2772 KB Output is correct
68 Correct 3 ms 2772 KB Output is correct
69 Correct 4 ms 2772 KB Output is correct
70 Correct 6 ms 2772 KB Output is correct
71 Correct 21 ms 7036 KB Output is correct
72 Correct 34 ms 21276 KB Output is correct
73 Correct 107 ms 21260 KB Output is correct
74 Correct 112 ms 21292 KB Output is correct
75 Correct 141 ms 21332 KB Output is correct
76 Correct 104 ms 21312 KB Output is correct
77 Correct 115 ms 21324 KB Output is correct
78 Correct 69 ms 21252 KB Output is correct
79 Correct 37 ms 21252 KB Output is correct
80 Correct 100 ms 21276 KB Output is correct
81 Correct 93 ms 21328 KB Output is correct
82 Correct 68 ms 21308 KB Output is correct
83 Correct 68 ms 21240 KB Output is correct
84 Correct 98 ms 21448 KB Output is correct
85 Correct 278 ms 43464 KB Output is correct
86 Correct 753 ms 93160 KB Output is correct
87 Correct 751 ms 93224 KB Output is correct
88 Correct 749 ms 93152 KB Output is correct
89 Correct 737 ms 93132 KB Output is correct
90 Correct 804 ms 93268 KB Output is correct
91 Correct 295 ms 92980 KB Output is correct
92 Correct 300 ms 92928 KB Output is correct
93 Correct 600 ms 93068 KB Output is correct
94 Correct 626 ms 93160 KB Output is correct
95 Correct 528 ms 93016 KB Output is correct
96 Correct 531 ms 93004 KB Output is correct
97 Incorrect 745 ms 93096 KB Output isn't correct
98 Halted 0 ms 0 KB -