Submission #567786

# Submission time Handle Problem Language Result Execution time Memory
567786 2022-05-24T07:55:18 Z tqbfjotld Copy and Paste 3 (JOI22_copypaste3) C++14
62 / 100
2021 ms 2097152 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==1) 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:79:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   79 | main(){
      | ^~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:81:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
copypaste3.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         scanf(" %c",&arr[x]);
      |         ~~~~~^~~~~~~~~~~~~~~
copypaste3.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |     scanf("%lld%lld%lld",&A,&B,&C);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 29812 KB Output is correct
2 Correct 12 ms 29772 KB Output is correct
3 Correct 13 ms 29780 KB Output is correct
4 Correct 17 ms 29780 KB Output is correct
5 Correct 16 ms 29804 KB Output is correct
6 Correct 12 ms 29740 KB Output is correct
7 Correct 13 ms 29780 KB Output is correct
8 Correct 13 ms 29772 KB Output is correct
9 Correct 12 ms 29732 KB Output is correct
10 Correct 15 ms 29780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 29932 KB Output is correct
2 Correct 12 ms 29780 KB Output is correct
3 Correct 522 ms 350636 KB Output is correct
4 Correct 623 ms 394476 KB Output is correct
5 Correct 688 ms 449468 KB Output is correct
6 Correct 819 ms 516676 KB Output is correct
7 Correct 1051 ms 593988 KB Output is correct
8 Correct 1029 ms 594124 KB Output is correct
9 Correct 1012 ms 594152 KB Output is correct
10 Correct 13 ms 29780 KB Output is correct
11 Correct 15 ms 29828 KB Output is correct
12 Correct 15 ms 29828 KB Output is correct
13 Correct 15 ms 29796 KB Output is correct
14 Correct 13 ms 29808 KB Output is correct
15 Correct 14 ms 29908 KB Output is correct
16 Correct 14 ms 30152 KB Output is correct
17 Correct 13 ms 29780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 29812 KB Output is correct
2 Correct 12 ms 29772 KB Output is correct
3 Correct 13 ms 29780 KB Output is correct
4 Correct 17 ms 29780 KB Output is correct
5 Correct 16 ms 29804 KB Output is correct
6 Correct 12 ms 29740 KB Output is correct
7 Correct 13 ms 29780 KB Output is correct
8 Correct 13 ms 29772 KB Output is correct
9 Correct 12 ms 29732 KB Output is correct
10 Correct 15 ms 29780 KB Output is correct
11 Correct 12 ms 29908 KB Output is correct
12 Correct 13 ms 29908 KB Output is correct
13 Correct 12 ms 30060 KB Output is correct
14 Correct 16 ms 29908 KB Output is correct
15 Correct 13 ms 30036 KB Output is correct
16 Correct 12 ms 29908 KB Output is correct
17 Correct 15 ms 29780 KB Output is correct
18 Correct 15 ms 29780 KB Output is correct
19 Correct 16 ms 29908 KB Output is correct
20 Correct 13 ms 29780 KB Output is correct
21 Correct 14 ms 30164 KB Output is correct
22 Correct 14 ms 30396 KB Output is correct
23 Correct 13 ms 30548 KB Output is correct
24 Correct 14 ms 30444 KB Output is correct
25 Correct 14 ms 30516 KB Output is correct
26 Correct 14 ms 30484 KB Output is correct
27 Correct 13 ms 30164 KB Output is correct
28 Correct 12 ms 30228 KB Output is correct
29 Correct 13 ms 30428 KB Output is correct
30 Correct 13 ms 30376 KB Output is correct
31 Correct 13 ms 30420 KB Output is correct
32 Correct 14 ms 30372 KB Output is correct
33 Correct 14 ms 30548 KB Output is correct
34 Correct 14 ms 29716 KB Output is correct
35 Correct 14 ms 29780 KB Output is correct
36 Correct 13 ms 29780 KB Output is correct
37 Correct 13 ms 29780 KB Output is correct
38 Correct 13 ms 29908 KB Output is correct
39 Correct 12 ms 30164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 29812 KB Output is correct
2 Correct 12 ms 29772 KB Output is correct
3 Correct 13 ms 29780 KB Output is correct
4 Correct 17 ms 29780 KB Output is correct
5 Correct 16 ms 29804 KB Output is correct
6 Correct 12 ms 29740 KB Output is correct
7 Correct 13 ms 29780 KB Output is correct
8 Correct 13 ms 29772 KB Output is correct
9 Correct 12 ms 29732 KB Output is correct
10 Correct 15 ms 29780 KB Output is correct
11 Correct 12 ms 29908 KB Output is correct
12 Correct 13 ms 29908 KB Output is correct
13 Correct 12 ms 30060 KB Output is correct
14 Correct 16 ms 29908 KB Output is correct
15 Correct 13 ms 30036 KB Output is correct
16 Correct 12 ms 29908 KB Output is correct
17 Correct 15 ms 29780 KB Output is correct
18 Correct 15 ms 29780 KB Output is correct
19 Correct 16 ms 29908 KB Output is correct
20 Correct 13 ms 29780 KB Output is correct
21 Correct 14 ms 30164 KB Output is correct
22 Correct 14 ms 30396 KB Output is correct
23 Correct 13 ms 30548 KB Output is correct
24 Correct 14 ms 30444 KB Output is correct
25 Correct 14 ms 30516 KB Output is correct
26 Correct 14 ms 30484 KB Output is correct
27 Correct 13 ms 30164 KB Output is correct
28 Correct 12 ms 30228 KB Output is correct
29 Correct 13 ms 30428 KB Output is correct
30 Correct 13 ms 30376 KB Output is correct
31 Correct 13 ms 30420 KB Output is correct
32 Correct 14 ms 30372 KB Output is correct
33 Correct 14 ms 30548 KB Output is correct
34 Correct 14 ms 29716 KB Output is correct
35 Correct 14 ms 29780 KB Output is correct
36 Correct 13 ms 29780 KB Output is correct
37 Correct 13 ms 29780 KB Output is correct
38 Correct 13 ms 29908 KB Output is correct
39 Correct 12 ms 30164 KB Output is correct
40 Correct 17 ms 34216 KB Output is correct
41 Correct 17 ms 35540 KB Output is correct
42 Correct 39 ms 52868 KB Output is correct
43 Correct 39 ms 53288 KB Output is correct
44 Correct 49 ms 53732 KB Output is correct
45 Correct 55 ms 53724 KB Output is correct
46 Correct 44 ms 53852 KB Output is correct
47 Correct 26 ms 39556 KB Output is correct
48 Correct 35 ms 46236 KB Output is correct
49 Correct 38 ms 49192 KB Output is correct
50 Correct 37 ms 49408 KB Output is correct
51 Correct 35 ms 45056 KB Output is correct
52 Correct 38 ms 45216 KB Output is correct
53 Correct 41 ms 53900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 29812 KB Output is correct
2 Correct 12 ms 29772 KB Output is correct
3 Correct 13 ms 29780 KB Output is correct
4 Correct 17 ms 29780 KB Output is correct
5 Correct 16 ms 29804 KB Output is correct
6 Correct 12 ms 29740 KB Output is correct
7 Correct 13 ms 29780 KB Output is correct
8 Correct 13 ms 29772 KB Output is correct
9 Correct 12 ms 29732 KB Output is correct
10 Correct 15 ms 29780 KB Output is correct
11 Correct 12 ms 29908 KB Output is correct
12 Correct 13 ms 29908 KB Output is correct
13 Correct 12 ms 30060 KB Output is correct
14 Correct 16 ms 29908 KB Output is correct
15 Correct 13 ms 30036 KB Output is correct
16 Correct 12 ms 29908 KB Output is correct
17 Correct 15 ms 29780 KB Output is correct
18 Correct 15 ms 29780 KB Output is correct
19 Correct 16 ms 29908 KB Output is correct
20 Correct 13 ms 29780 KB Output is correct
21 Correct 14 ms 30164 KB Output is correct
22 Correct 14 ms 30396 KB Output is correct
23 Correct 13 ms 30548 KB Output is correct
24 Correct 14 ms 30444 KB Output is correct
25 Correct 14 ms 30516 KB Output is correct
26 Correct 14 ms 30484 KB Output is correct
27 Correct 13 ms 30164 KB Output is correct
28 Correct 12 ms 30228 KB Output is correct
29 Correct 13 ms 30428 KB Output is correct
30 Correct 13 ms 30376 KB Output is correct
31 Correct 13 ms 30420 KB Output is correct
32 Correct 14 ms 30372 KB Output is correct
33 Correct 14 ms 30548 KB Output is correct
34 Correct 14 ms 29716 KB Output is correct
35 Correct 14 ms 29780 KB Output is correct
36 Correct 13 ms 29780 KB Output is correct
37 Correct 13 ms 29780 KB Output is correct
38 Correct 13 ms 29908 KB Output is correct
39 Correct 12 ms 30164 KB Output is correct
40 Correct 17 ms 34216 KB Output is correct
41 Correct 17 ms 35540 KB Output is correct
42 Correct 39 ms 52868 KB Output is correct
43 Correct 39 ms 53288 KB Output is correct
44 Correct 49 ms 53732 KB Output is correct
45 Correct 55 ms 53724 KB Output is correct
46 Correct 44 ms 53852 KB Output is correct
47 Correct 26 ms 39556 KB Output is correct
48 Correct 35 ms 46236 KB Output is correct
49 Correct 38 ms 49192 KB Output is correct
50 Correct 37 ms 49408 KB Output is correct
51 Correct 35 ms 45056 KB Output is correct
52 Correct 38 ms 45216 KB Output is correct
53 Correct 41 ms 53900 KB Output is correct
54 Correct 166 ms 143072 KB Output is correct
55 Correct 156 ms 131252 KB Output is correct
56 Correct 648 ms 593884 KB Output is correct
57 Correct 717 ms 597092 KB Output is correct
58 Correct 691 ms 599252 KB Output is correct
59 Correct 688 ms 600132 KB Output is correct
60 Correct 750 ms 600740 KB Output is correct
61 Correct 619 ms 337224 KB Output is correct
62 Correct 180 ms 142712 KB Output is correct
63 Correct 655 ms 489060 KB Output is correct
64 Correct 694 ms 489088 KB Output is correct
65 Correct 733 ms 366968 KB Output is correct
66 Correct 793 ms 366944 KB Output is correct
67 Correct 698 ms 600716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 29812 KB Output is correct
2 Correct 12 ms 29772 KB Output is correct
3 Correct 13 ms 29780 KB Output is correct
4 Correct 17 ms 29780 KB Output is correct
5 Correct 16 ms 29804 KB Output is correct
6 Correct 12 ms 29740 KB Output is correct
7 Correct 13 ms 29780 KB Output is correct
8 Correct 13 ms 29772 KB Output is correct
9 Correct 12 ms 29732 KB Output is correct
10 Correct 15 ms 29780 KB Output is correct
11 Correct 12 ms 29932 KB Output is correct
12 Correct 12 ms 29780 KB Output is correct
13 Correct 522 ms 350636 KB Output is correct
14 Correct 623 ms 394476 KB Output is correct
15 Correct 688 ms 449468 KB Output is correct
16 Correct 819 ms 516676 KB Output is correct
17 Correct 1051 ms 593988 KB Output is correct
18 Correct 1029 ms 594124 KB Output is correct
19 Correct 1012 ms 594152 KB Output is correct
20 Correct 13 ms 29780 KB Output is correct
21 Correct 15 ms 29828 KB Output is correct
22 Correct 15 ms 29828 KB Output is correct
23 Correct 15 ms 29796 KB Output is correct
24 Correct 13 ms 29808 KB Output is correct
25 Correct 14 ms 29908 KB Output is correct
26 Correct 14 ms 30152 KB Output is correct
27 Correct 13 ms 29780 KB Output is correct
28 Correct 12 ms 29908 KB Output is correct
29 Correct 13 ms 29908 KB Output is correct
30 Correct 12 ms 30060 KB Output is correct
31 Correct 16 ms 29908 KB Output is correct
32 Correct 13 ms 30036 KB Output is correct
33 Correct 12 ms 29908 KB Output is correct
34 Correct 15 ms 29780 KB Output is correct
35 Correct 15 ms 29780 KB Output is correct
36 Correct 16 ms 29908 KB Output is correct
37 Correct 13 ms 29780 KB Output is correct
38 Correct 14 ms 30164 KB Output is correct
39 Correct 14 ms 30396 KB Output is correct
40 Correct 13 ms 30548 KB Output is correct
41 Correct 14 ms 30444 KB Output is correct
42 Correct 14 ms 30516 KB Output is correct
43 Correct 14 ms 30484 KB Output is correct
44 Correct 13 ms 30164 KB Output is correct
45 Correct 12 ms 30228 KB Output is correct
46 Correct 13 ms 30428 KB Output is correct
47 Correct 13 ms 30376 KB Output is correct
48 Correct 13 ms 30420 KB Output is correct
49 Correct 14 ms 30372 KB Output is correct
50 Correct 14 ms 30548 KB Output is correct
51 Correct 14 ms 29716 KB Output is correct
52 Correct 14 ms 29780 KB Output is correct
53 Correct 13 ms 29780 KB Output is correct
54 Correct 13 ms 29780 KB Output is correct
55 Correct 13 ms 29908 KB Output is correct
56 Correct 12 ms 30164 KB Output is correct
57 Correct 17 ms 34216 KB Output is correct
58 Correct 17 ms 35540 KB Output is correct
59 Correct 39 ms 52868 KB Output is correct
60 Correct 39 ms 53288 KB Output is correct
61 Correct 49 ms 53732 KB Output is correct
62 Correct 55 ms 53724 KB Output is correct
63 Correct 44 ms 53852 KB Output is correct
64 Correct 26 ms 39556 KB Output is correct
65 Correct 35 ms 46236 KB Output is correct
66 Correct 38 ms 49192 KB Output is correct
67 Correct 37 ms 49408 KB Output is correct
68 Correct 35 ms 45056 KB Output is correct
69 Correct 38 ms 45216 KB Output is correct
70 Correct 41 ms 53900 KB Output is correct
71 Correct 166 ms 143072 KB Output is correct
72 Correct 156 ms 131252 KB Output is correct
73 Correct 648 ms 593884 KB Output is correct
74 Correct 717 ms 597092 KB Output is correct
75 Correct 691 ms 599252 KB Output is correct
76 Correct 688 ms 600132 KB Output is correct
77 Correct 750 ms 600740 KB Output is correct
78 Correct 619 ms 337224 KB Output is correct
79 Correct 180 ms 142712 KB Output is correct
80 Correct 655 ms 489060 KB Output is correct
81 Correct 694 ms 489088 KB Output is correct
82 Correct 733 ms 366968 KB Output is correct
83 Correct 793 ms 366944 KB Output is correct
84 Correct 698 ms 600716 KB Output is correct
85 Correct 2021 ms 1438268 KB Output is correct
86 Runtime error 1464 ms 2097152 KB Execution killed with signal 9
87 Halted 0 ms 0 KB -