답안 #592449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
592449 2022-07-09T08:16:04 Z 79brue Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
683 ms 82932 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll MOD = 1000000000039LL;

int n;
ll A, B, C;
char str[2502];
int arr[2502];
ll hashVal[2502][2502];
ll DP[2502][2502];
int nxt[2502];

int main(){
    scanf("%d %s %lld %lld %lld", &n, str+1, &A, &B, &C);
    for(int i=1; i<=n; i++) arr[i] = str[i] - 'a';
    for(int i=1; i<=n; i++){
        for(int j=i; j<=n; j++){
            hashVal[i][j] = (hashVal[i][j-1] * 1000003 + arr[j]) % MOD;
        }
    }
    for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) DP[i][j] = 1e18;
    for(int i=1; i<=n; i++) DP[i][i] = A;

    for(int d=0; d<n; d++){
        map<ll, int> mp;
        for(int i=1; i+d<=n; i++){
            int j = i+d;
            DP[i][j] = min({DP[i][j], DP[i+1][j]+A, DP[i][j-1]+A});
        }
        for(int i=n-d; i>=1; i--){
            int j = i+d;
            if(mp[hashVal[i][j]]) nxt[i] = mp[hashVal[i][j]];
            else nxt[i] = 0;
            if(j+d<=n) mp[hashVal[j][j+d]] = j;
        }
        for(int i=1; i+d<=n; i++){
            int e = i+d;
            int cnt = 1;
            while(nxt[e-d]){
                e = nxt[e-d]+d;
                cnt++;
//                printf("Set %d %d to %lld\n", i, e, DP[i][i+d] + B + C * cnt + A * (e-i+1 - cnt*(d+1)));
                DP[i][e] = min(DP[i][e], DP[i][i+d] + B + C * cnt + A * (e-i+1 - cnt*(d+1)));
            }
//            printf("%d %d: %lld\n", i, i+d, DP[i][i+d]);
        }
    }

    printf("%lld", DP[1][n]);
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %s %lld %lld %lld", &n, str+1, &A, &B, &C);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 155 ms 54228 KB Output is correct
4 Correct 192 ms 62120 KB Output is correct
5 Correct 222 ms 68604 KB Output is correct
6 Correct 254 ms 75348 KB Output is correct
7 Correct 326 ms 82768 KB Output is correct
8 Correct 296 ms 82764 KB Output is correct
9 Correct 308 ms 82764 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 468 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 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 352 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 0 ms 468 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 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 352 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 0 ms 468 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 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 468 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 2 ms 2260 KB Output is correct
42 Correct 4 ms 2388 KB Output is correct
43 Correct 4 ms 2388 KB Output is correct
44 Correct 4 ms 2388 KB Output is correct
45 Correct 4 ms 2384 KB Output is correct
46 Correct 4 ms 2388 KB Output is correct
47 Correct 3 ms 2260 KB Output is correct
48 Correct 3 ms 2260 KB Output is correct
49 Correct 4 ms 2260 KB Output is correct
50 Correct 4 ms 2388 KB Output is correct
51 Correct 3 ms 2260 KB Output is correct
52 Correct 3 ms 2260 KB Output is correct
53 Correct 4 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 352 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 0 ms 468 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 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 468 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 2 ms 2260 KB Output is correct
42 Correct 4 ms 2388 KB Output is correct
43 Correct 4 ms 2388 KB Output is correct
44 Correct 4 ms 2388 KB Output is correct
45 Correct 4 ms 2384 KB Output is correct
46 Correct 4 ms 2388 KB Output is correct
47 Correct 3 ms 2260 KB Output is correct
48 Correct 3 ms 2260 KB Output is correct
49 Correct 4 ms 2260 KB Output is correct
50 Correct 4 ms 2388 KB Output is correct
51 Correct 3 ms 2260 KB Output is correct
52 Correct 3 ms 2260 KB Output is correct
53 Correct 4 ms 2260 KB Output is correct
54 Correct 18 ms 6284 KB Output is correct
55 Correct 33 ms 20052 KB Output is correct
56 Correct 97 ms 20160 KB Output is correct
57 Correct 96 ms 20104 KB Output is correct
58 Correct 97 ms 20180 KB Output is correct
59 Correct 96 ms 20160 KB Output is correct
60 Correct 96 ms 20164 KB Output is correct
61 Correct 80 ms 20116 KB Output is correct
62 Correct 35 ms 20096 KB Output is correct
63 Correct 92 ms 20136 KB Output is correct
64 Correct 91 ms 20052 KB Output is correct
65 Correct 79 ms 20120 KB Output is correct
66 Correct 79 ms 20120 KB Output is correct
67 Correct 96 ms 20180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 155 ms 54228 KB Output is correct
14 Correct 192 ms 62120 KB Output is correct
15 Correct 222 ms 68604 KB Output is correct
16 Correct 254 ms 75348 KB Output is correct
17 Correct 326 ms 82768 KB Output is correct
18 Correct 296 ms 82764 KB Output is correct
19 Correct 308 ms 82764 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 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 468 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 0 ms 304 KB Output is correct
32 Correct 0 ms 468 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 352 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 468 KB Output is correct
39 Correct 0 ms 468 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
41 Correct 0 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 0 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 0 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 0 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 0 ms 468 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 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 0 ms 340 KB Output is correct
56 Correct 0 ms 468 KB Output is correct
57 Correct 1 ms 980 KB Output is correct
58 Correct 2 ms 2260 KB Output is correct
59 Correct 4 ms 2388 KB Output is correct
60 Correct 4 ms 2388 KB Output is correct
61 Correct 4 ms 2388 KB Output is correct
62 Correct 4 ms 2384 KB Output is correct
63 Correct 4 ms 2388 KB Output is correct
64 Correct 3 ms 2260 KB Output is correct
65 Correct 3 ms 2260 KB Output is correct
66 Correct 4 ms 2260 KB Output is correct
67 Correct 4 ms 2388 KB Output is correct
68 Correct 3 ms 2260 KB Output is correct
69 Correct 3 ms 2260 KB Output is correct
70 Correct 4 ms 2260 KB Output is correct
71 Correct 18 ms 6284 KB Output is correct
72 Correct 33 ms 20052 KB Output is correct
73 Correct 97 ms 20160 KB Output is correct
74 Correct 96 ms 20104 KB Output is correct
75 Correct 97 ms 20180 KB Output is correct
76 Correct 96 ms 20160 KB Output is correct
77 Correct 96 ms 20164 KB Output is correct
78 Correct 80 ms 20116 KB Output is correct
79 Correct 35 ms 20096 KB Output is correct
80 Correct 92 ms 20136 KB Output is correct
81 Correct 91 ms 20052 KB Output is correct
82 Correct 79 ms 20120 KB Output is correct
83 Correct 79 ms 20120 KB Output is correct
84 Correct 96 ms 20180 KB Output is correct
85 Correct 263 ms 42440 KB Output is correct
86 Correct 677 ms 82932 KB Output is correct
87 Correct 683 ms 82928 KB Output is correct
88 Correct 673 ms 82860 KB Output is correct
89 Correct 669 ms 82924 KB Output is correct
90 Correct 663 ms 82864 KB Output is correct
91 Correct 314 ms 82772 KB Output is correct
92 Correct 269 ms 82664 KB Output is correct
93 Correct 636 ms 82848 KB Output is correct
94 Correct 643 ms 82900 KB Output is correct
95 Correct 613 ms 82716 KB Output is correct
96 Correct 618 ms 82828 KB Output is correct
97 Correct 670 ms 82908 KB Output is correct