Submission #567777

# Submission time Handle Problem Language Result Execution time Memory
567777 2022-05-24T07:40:12 Z tqbfjotld Copy and Paste 3 (JOI22_copypaste3) C++14
30 / 100
3000 ms 594072 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

char arr[2505];
int A,B,C;
int mem[2505*1505];
int id[2505][2505];
int ct = 1;

struct node{
    int nid, len;
    vector<int> vals;
    node*ch[26];
    vector<int> decomp[15];
    node(int _len){
        nid = ct++;
        len = _len;
        for (int x = 0; x<26; x++){
            ch[x] = 0;
        }
    }
    void construct(){
        //printf("call construct len %lld\n",len);
        for (int x = 0; x<vals.size(); x++){
            decomp[0].push_back(lower_bound(vals.begin(),vals.end(),vals[x]+len)-vals.begin());
        }
        decomp[0].push_back(vals.size());
        for (int x = 1; x<15; x++){
            for (int y = 0; y<=vals.size(); y++){
                decomp[x].push_back(decomp[x-1][decomp[x-1][y]]);
            }
        }
    }
    void constructall(){
        construct();
        for (int x = 0; x<26; x++){
            if (ch[x]!=0){
                ch[x]->constructall();
            }
        }
    }
    int cntocc(int st, int en){
        //printf("call cntocc %lld %lld, len %lld\n",st,en,len);
        int cur = lower_bound(vals.begin(),vals.end(),st)-vals.begin();
        int ans = 1;
        int r = upper_bound(vals.begin(),vals.end(),en-len)-vals.begin();
        for (int x = 14; x>=0; x--){
            if (decomp[x][cur]<r){
                ans += (1<<x);
                cur = decomp[x][cur];
            }
        }
        return ans;
    }
}*rt;

node* pt[2505][2505];

int cntocc(int a, int b, int st, int en){
    return pt[a][b]->cntocc(st,en);
}

int func(int a, int b){
    if (mem[id[a][b]]!=-1) return mem[id[a][b]];
    if (a==b) return 0;
    int ans = func(a+1,b)+A;
    for (int x = 1; x<b-a; x++){
        int t = func(a,a+x);
        int t2 = cntocc(a,a+x,a,b);
        ans = min(ans,t+B+t2*C+(b-a-x*t2)*A);
        if (t2==0) break;
    }
    //printf("func %lld %lld = %lld\n",a,b,ans);
    return mem[id[a][b]] = ans;
}

main(){
    int n;
    scanf("%lld",&n);
    for (int x = 0; x<n; x++){
        scanf(" %c",&arr[x]);
    }
    scanf("%lld%lld%lld",&A,&B,&C);
    memset(mem,-1,sizeof(mem));
    for (int x = 0; x<n; x++){
        if (rt==0){
            rt = new node(0);
        }
        node *cur = rt;
        for (int y = x+1; y<=n; y++){
            if (cur->ch[arr[y-1]-'a']==0){
                cur->ch[arr[y-1]-'a'] = new node(y-x);
            }
            cur = cur->ch[arr[y-1]-'a'];
            cur->vals.push_back(x);
            pt[x][y] = cur;
            id[x][y] = cur->nid;
        }
    }
    rt->constructall();
    printf("%lld",func(0,n));
}

Compilation message

copypaste3.cpp: In member function 'void node::construct()':
copypaste3.cpp:25:26: 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]
   25 |         for (int x = 0; x<vals.size(); x++){
      |                         ~^~~~~~~~~~~~
copypaste3.cpp:30:30: 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]
   30 |             for (int y = 0; y<=vals.size(); y++){
      |                             ~^~~~~~~~~~~~~
copypaste3.cpp: At global scope:
copypaste3.cpp:78:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   78 | main(){
      | ^~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
copypaste3.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         scanf(" %c",&arr[x]);
      |         ~~~~~^~~~~~~~~~~~~~~
copypaste3.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |     scanf("%lld%lld%lld",&A,&B,&C);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 29780 KB Output is correct
2 Correct 12 ms 29780 KB Output is correct
3 Correct 14 ms 29780 KB Output is correct
4 Correct 12 ms 29780 KB Output is correct
5 Correct 16 ms 29780 KB Output is correct
6 Correct 13 ms 29756 KB Output is correct
7 Correct 12 ms 29780 KB Output is correct
8 Correct 12 ms 29780 KB Output is correct
9 Correct 13 ms 29752 KB Output is correct
10 Correct 13 ms 29780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 29988 KB Output is correct
2 Correct 16 ms 29776 KB Output is correct
3 Correct 830 ms 350544 KB Output is correct
4 Correct 966 ms 394592 KB Output is correct
5 Correct 1157 ms 449432 KB Output is correct
6 Correct 1481 ms 516684 KB Output is correct
7 Correct 2005 ms 594052 KB Output is correct
8 Correct 2183 ms 594068 KB Output is correct
9 Correct 1962 ms 594072 KB Output is correct
10 Correct 13 ms 29780 KB Output is correct
11 Correct 13 ms 29780 KB Output is correct
12 Correct 12 ms 29780 KB Output is correct
13 Correct 13 ms 29816 KB Output is correct
14 Correct 15 ms 29908 KB Output is correct
15 Correct 13 ms 29908 KB Output is correct
16 Correct 14 ms 30136 KB Output is correct
17 Correct 15 ms 29748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 29780 KB Output is correct
2 Correct 12 ms 29780 KB Output is correct
3 Correct 14 ms 29780 KB Output is correct
4 Correct 12 ms 29780 KB Output is correct
5 Correct 16 ms 29780 KB Output is correct
6 Correct 13 ms 29756 KB Output is correct
7 Correct 12 ms 29780 KB Output is correct
8 Correct 12 ms 29780 KB Output is correct
9 Correct 13 ms 29752 KB Output is correct
10 Correct 13 ms 29780 KB Output is correct
11 Correct 13 ms 29908 KB Output is correct
12 Correct 16 ms 29880 KB Output is correct
13 Correct 17 ms 30072 KB Output is correct
14 Correct 18 ms 29808 KB Output is correct
15 Correct 16 ms 30036 KB Output is correct
16 Correct 13 ms 29908 KB Output is correct
17 Correct 13 ms 29780 KB Output is correct
18 Correct 16 ms 29772 KB Output is correct
19 Correct 13 ms 30004 KB Output is correct
20 Correct 13 ms 29796 KB Output is correct
21 Correct 13 ms 30080 KB Output is correct
22 Correct 13 ms 30420 KB Output is correct
23 Correct 13 ms 30488 KB Output is correct
24 Correct 14 ms 30548 KB Output is correct
25 Correct 13 ms 30472 KB Output is correct
26 Correct 13 ms 30536 KB Output is correct
27 Correct 14 ms 30164 KB Output is correct
28 Correct 14 ms 30160 KB Output is correct
29 Correct 14 ms 30420 KB Output is correct
30 Correct 18 ms 30376 KB Output is correct
31 Correct 18 ms 30412 KB Output is correct
32 Correct 15 ms 30420 KB Output is correct
33 Correct 14 ms 30548 KB Output is correct
34 Correct 12 ms 29768 KB Output is correct
35 Correct 13 ms 29780 KB Output is correct
36 Correct 12 ms 29860 KB Output is correct
37 Correct 14 ms 29908 KB Output is correct
38 Correct 14 ms 29908 KB Output is correct
39 Correct 15 ms 30164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 29780 KB Output is correct
2 Correct 12 ms 29780 KB Output is correct
3 Correct 14 ms 29780 KB Output is correct
4 Correct 12 ms 29780 KB Output is correct
5 Correct 16 ms 29780 KB Output is correct
6 Correct 13 ms 29756 KB Output is correct
7 Correct 12 ms 29780 KB Output is correct
8 Correct 12 ms 29780 KB Output is correct
9 Correct 13 ms 29752 KB Output is correct
10 Correct 13 ms 29780 KB Output is correct
11 Correct 13 ms 29908 KB Output is correct
12 Correct 16 ms 29880 KB Output is correct
13 Correct 17 ms 30072 KB Output is correct
14 Correct 18 ms 29808 KB Output is correct
15 Correct 16 ms 30036 KB Output is correct
16 Correct 13 ms 29908 KB Output is correct
17 Correct 13 ms 29780 KB Output is correct
18 Correct 16 ms 29772 KB Output is correct
19 Correct 13 ms 30004 KB Output is correct
20 Correct 13 ms 29796 KB Output is correct
21 Correct 13 ms 30080 KB Output is correct
22 Correct 13 ms 30420 KB Output is correct
23 Correct 13 ms 30488 KB Output is correct
24 Correct 14 ms 30548 KB Output is correct
25 Correct 13 ms 30472 KB Output is correct
26 Correct 13 ms 30536 KB Output is correct
27 Correct 14 ms 30164 KB Output is correct
28 Correct 14 ms 30160 KB Output is correct
29 Correct 14 ms 30420 KB Output is correct
30 Correct 18 ms 30376 KB Output is correct
31 Correct 18 ms 30412 KB Output is correct
32 Correct 15 ms 30420 KB Output is correct
33 Correct 14 ms 30548 KB Output is correct
34 Correct 12 ms 29768 KB Output is correct
35 Correct 13 ms 29780 KB Output is correct
36 Correct 12 ms 29860 KB Output is correct
37 Correct 14 ms 29908 KB Output is correct
38 Correct 14 ms 29908 KB Output is correct
39 Correct 15 ms 30164 KB Output is correct
40 Correct 22 ms 34260 KB Output is correct
41 Correct 18 ms 35544 KB Output is correct
42 Correct 79 ms 52940 KB Output is correct
43 Correct 80 ms 53460 KB Output is correct
44 Correct 95 ms 53696 KB Output is correct
45 Correct 80 ms 53836 KB Output is correct
46 Correct 73 ms 53836 KB Output is correct
47 Correct 40 ms 39680 KB Output is correct
48 Correct 62 ms 46292 KB Output is correct
49 Correct 71 ms 49216 KB Output is correct
50 Correct 70 ms 49436 KB Output is correct
51 Correct 80 ms 45248 KB Output is correct
52 Correct 81 ms 45356 KB Output is correct
53 Correct 75 ms 53896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 29780 KB Output is correct
2 Correct 12 ms 29780 KB Output is correct
3 Correct 14 ms 29780 KB Output is correct
4 Correct 12 ms 29780 KB Output is correct
5 Correct 16 ms 29780 KB Output is correct
6 Correct 13 ms 29756 KB Output is correct
7 Correct 12 ms 29780 KB Output is correct
8 Correct 12 ms 29780 KB Output is correct
9 Correct 13 ms 29752 KB Output is correct
10 Correct 13 ms 29780 KB Output is correct
11 Correct 13 ms 29908 KB Output is correct
12 Correct 16 ms 29880 KB Output is correct
13 Correct 17 ms 30072 KB Output is correct
14 Correct 18 ms 29808 KB Output is correct
15 Correct 16 ms 30036 KB Output is correct
16 Correct 13 ms 29908 KB Output is correct
17 Correct 13 ms 29780 KB Output is correct
18 Correct 16 ms 29772 KB Output is correct
19 Correct 13 ms 30004 KB Output is correct
20 Correct 13 ms 29796 KB Output is correct
21 Correct 13 ms 30080 KB Output is correct
22 Correct 13 ms 30420 KB Output is correct
23 Correct 13 ms 30488 KB Output is correct
24 Correct 14 ms 30548 KB Output is correct
25 Correct 13 ms 30472 KB Output is correct
26 Correct 13 ms 30536 KB Output is correct
27 Correct 14 ms 30164 KB Output is correct
28 Correct 14 ms 30160 KB Output is correct
29 Correct 14 ms 30420 KB Output is correct
30 Correct 18 ms 30376 KB Output is correct
31 Correct 18 ms 30412 KB Output is correct
32 Correct 15 ms 30420 KB Output is correct
33 Correct 14 ms 30548 KB Output is correct
34 Correct 12 ms 29768 KB Output is correct
35 Correct 13 ms 29780 KB Output is correct
36 Correct 12 ms 29860 KB Output is correct
37 Correct 14 ms 29908 KB Output is correct
38 Correct 14 ms 29908 KB Output is correct
39 Correct 15 ms 30164 KB Output is correct
40 Correct 22 ms 34260 KB Output is correct
41 Correct 18 ms 35544 KB Output is correct
42 Correct 79 ms 52940 KB Output is correct
43 Correct 80 ms 53460 KB Output is correct
44 Correct 95 ms 53696 KB Output is correct
45 Correct 80 ms 53836 KB Output is correct
46 Correct 73 ms 53836 KB Output is correct
47 Correct 40 ms 39680 KB Output is correct
48 Correct 62 ms 46292 KB Output is correct
49 Correct 71 ms 49216 KB Output is correct
50 Correct 70 ms 49436 KB Output is correct
51 Correct 80 ms 45248 KB Output is correct
52 Correct 81 ms 45356 KB Output is correct
53 Correct 75 ms 53896 KB Output is correct
54 Correct 553 ms 143152 KB Output is correct
55 Correct 224 ms 131296 KB Output is correct
56 Execution timed out 3107 ms 593904 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 29780 KB Output is correct
2 Correct 12 ms 29780 KB Output is correct
3 Correct 14 ms 29780 KB Output is correct
4 Correct 12 ms 29780 KB Output is correct
5 Correct 16 ms 29780 KB Output is correct
6 Correct 13 ms 29756 KB Output is correct
7 Correct 12 ms 29780 KB Output is correct
8 Correct 12 ms 29780 KB Output is correct
9 Correct 13 ms 29752 KB Output is correct
10 Correct 13 ms 29780 KB Output is correct
11 Correct 13 ms 29988 KB Output is correct
12 Correct 16 ms 29776 KB Output is correct
13 Correct 830 ms 350544 KB Output is correct
14 Correct 966 ms 394592 KB Output is correct
15 Correct 1157 ms 449432 KB Output is correct
16 Correct 1481 ms 516684 KB Output is correct
17 Correct 2005 ms 594052 KB Output is correct
18 Correct 2183 ms 594068 KB Output is correct
19 Correct 1962 ms 594072 KB Output is correct
20 Correct 13 ms 29780 KB Output is correct
21 Correct 13 ms 29780 KB Output is correct
22 Correct 12 ms 29780 KB Output is correct
23 Correct 13 ms 29816 KB Output is correct
24 Correct 15 ms 29908 KB Output is correct
25 Correct 13 ms 29908 KB Output is correct
26 Correct 14 ms 30136 KB Output is correct
27 Correct 15 ms 29748 KB Output is correct
28 Correct 13 ms 29908 KB Output is correct
29 Correct 16 ms 29880 KB Output is correct
30 Correct 17 ms 30072 KB Output is correct
31 Correct 18 ms 29808 KB Output is correct
32 Correct 16 ms 30036 KB Output is correct
33 Correct 13 ms 29908 KB Output is correct
34 Correct 13 ms 29780 KB Output is correct
35 Correct 16 ms 29772 KB Output is correct
36 Correct 13 ms 30004 KB Output is correct
37 Correct 13 ms 29796 KB Output is correct
38 Correct 13 ms 30080 KB Output is correct
39 Correct 13 ms 30420 KB Output is correct
40 Correct 13 ms 30488 KB Output is correct
41 Correct 14 ms 30548 KB Output is correct
42 Correct 13 ms 30472 KB Output is correct
43 Correct 13 ms 30536 KB Output is correct
44 Correct 14 ms 30164 KB Output is correct
45 Correct 14 ms 30160 KB Output is correct
46 Correct 14 ms 30420 KB Output is correct
47 Correct 18 ms 30376 KB Output is correct
48 Correct 18 ms 30412 KB Output is correct
49 Correct 15 ms 30420 KB Output is correct
50 Correct 14 ms 30548 KB Output is correct
51 Correct 12 ms 29768 KB Output is correct
52 Correct 13 ms 29780 KB Output is correct
53 Correct 12 ms 29860 KB Output is correct
54 Correct 14 ms 29908 KB Output is correct
55 Correct 14 ms 29908 KB Output is correct
56 Correct 15 ms 30164 KB Output is correct
57 Correct 22 ms 34260 KB Output is correct
58 Correct 18 ms 35544 KB Output is correct
59 Correct 79 ms 52940 KB Output is correct
60 Correct 80 ms 53460 KB Output is correct
61 Correct 95 ms 53696 KB Output is correct
62 Correct 80 ms 53836 KB Output is correct
63 Correct 73 ms 53836 KB Output is correct
64 Correct 40 ms 39680 KB Output is correct
65 Correct 62 ms 46292 KB Output is correct
66 Correct 71 ms 49216 KB Output is correct
67 Correct 70 ms 49436 KB Output is correct
68 Correct 80 ms 45248 KB Output is correct
69 Correct 81 ms 45356 KB Output is correct
70 Correct 75 ms 53896 KB Output is correct
71 Correct 553 ms 143152 KB Output is correct
72 Correct 224 ms 131296 KB Output is correct
73 Execution timed out 3107 ms 593904 KB Time limit exceeded
74 Halted 0 ms 0 KB -