답안 #568025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568025 2022-05-24T14:02:23 Z dantoh000 Copy and Paste 3 (JOI22_copypaste3) C++14
57 / 100
3000 ms 41300 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 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 = 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){
            groups.clear();
            for (int j = 0; j+i <= n; j++){
                GRP[j] = hsh[j][j+i];
                groups[GRP[j]].push_back(j);
            }
            for (int j = 0; j+i <= n; j++){
                int G = GRP[j];
                auto 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);
                    while (idx < groups[G].size() && groups[G][idx] < R) idx++;
                    if (idx == groups[G].size()) break;
                    cur = groups[G][idx];
                }
            }
        }

    }

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

Compilation message

copypaste3.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main(){
      | ^~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:52:32: 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]
   52 |                     while (idx < groups[G].size() && groups[G][idx] < R) idx++;
      |                            ~~~~^~~~~~~~~~~~~~~~~~
copypaste3.cpp:53:29: 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]
   53 |                     if (idx == groups[G].size()) break;
      |                         ~~~~^~~~~~~~~~~~~~~~~~~
copypaste3.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
copypaste3.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%lld%lld%lld",&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 1 ms 340 KB Output is correct
4 Correct 0 ms 212 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 3078 ms 41300 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 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 468 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 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 1 ms 468 KB Output is correct
28 Correct 1 ms 468 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 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 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 1 ms 340 KB Output is correct
4 Correct 0 ms 212 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 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 468 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 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 1 ms 468 KB Output is correct
28 Correct 1 ms 468 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 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 11 ms 2132 KB Output is correct
42 Correct 8 ms 2264 KB Output is correct
43 Correct 7 ms 2260 KB Output is correct
44 Correct 7 ms 2272 KB Output is correct
45 Correct 6 ms 2260 KB Output is correct
46 Correct 6 ms 2260 KB Output is correct
47 Correct 6 ms 2132 KB Output is correct
48 Correct 6 ms 2132 KB Output is correct
49 Correct 9 ms 2132 KB Output is correct
50 Correct 8 ms 2260 KB Output is correct
51 Correct 8 ms 2260 KB Output is correct
52 Correct 7 ms 2132 KB Output is correct
53 Correct 6 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 1 ms 340 KB Output is correct
4 Correct 0 ms 212 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 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 468 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 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 1 ms 468 KB Output is correct
28 Correct 1 ms 468 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 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 11 ms 2132 KB Output is correct
42 Correct 8 ms 2264 KB Output is correct
43 Correct 7 ms 2260 KB Output is correct
44 Correct 7 ms 2272 KB Output is correct
45 Correct 6 ms 2260 KB Output is correct
46 Correct 6 ms 2260 KB Output is correct
47 Correct 6 ms 2132 KB Output is correct
48 Correct 6 ms 2132 KB Output is correct
49 Correct 9 ms 2132 KB Output is correct
50 Correct 8 ms 2260 KB Output is correct
51 Correct 8 ms 2260 KB Output is correct
52 Correct 7 ms 2132 KB Output is correct
53 Correct 6 ms 2260 KB Output is correct
54 Correct 39 ms 5552 KB Output is correct
55 Correct 841 ms 16212 KB Output is correct
56 Correct 179 ms 16332 KB Output is correct
57 Correct 176 ms 16452 KB Output is correct
58 Correct 163 ms 16388 KB Output is correct
59 Correct 167 ms 16376 KB Output is correct
60 Correct 184 ms 16368 KB Output is correct
61 Correct 200 ms 16332 KB Output is correct
62 Correct 686 ms 16276 KB Output is correct
63 Correct 182 ms 16332 KB Output is correct
64 Correct 202 ms 16336 KB Output is correct
65 Correct 251 ms 16276 KB Output is correct
66 Correct 256 ms 16424 KB Output is correct
67 Correct 183 ms 16372 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 1 ms 340 KB Output is correct
4 Correct 0 ms 212 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Execution timed out 3078 ms 41300 KB Time limit exceeded
14 Halted 0 ms 0 KB -