답안 #567792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567792 2022-05-24T08:12:10 Z tqbfjotld Copy and Paste 3 (JOI22_copypaste3) C++14
62 / 100
3000 ms 1183848 KB
#include <bits/stdc++.h>
using namespace std;

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

struct node{
    int nid;
    short len;
    vector<short> vals;
    node*ch[26];
    vector<vector<short> >decomp;
    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);
        int lgx = 1;
        while ((1<<(lgx))<=vals.size()) lgx++;
        decomp.resize(lgx);
        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<decomp.size(); 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 = (int)decomp.size()-1; 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);
}


long long func(int a, int b){
    if (a==b) return 0;
    if (mem[pt[a][b]->nid]!=-1) return mem[pt[a][b]->nid];
    long long ans = func(a+1,b)+A;
    for (int x = 1; x<b-a; x++){
        long long 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[pt[a][b]->nid] = ans;
}

main(){
    int n;
    scanf("%d",&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;
        }
    }
    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: 'int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         while ((1<<(lgx))<=vals.size()) lgx++;
      |                ~~~~~~~~~~^~~~~~~~~~~~~
copypaste3.cpp:27:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for (int x = 0; x<vals.size(); x++){
      |                         ~^~~~~~~~~~~~
copypaste3.cpp:31:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<short int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for (int x = 1; x<decomp.size(); x++){
      |                         ~^~~~~~~~~~~~~~
copypaste3.cpp:32:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             for (int y = 0; y<=vals.size(); y++){
      |                             ~^~~~~~~~~~~~~
copypaste3.cpp: At global scope:
copypaste3.cpp:81:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   81 | main(){
      | ^~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
copypaste3.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         scanf(" %c",&arr[x]);
      |         ~~~~~^~~~~~~~~~~~~~~
copypaste3.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |     scanf("%lld%lld%lld",&A,&B,&C);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 25812 KB Output is correct
2 Correct 11 ms 25912 KB Output is correct
3 Correct 13 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 12 ms 25812 KB Output is correct
6 Correct 11 ms 25812 KB Output is correct
7 Correct 11 ms 25892 KB Output is correct
8 Correct 11 ms 25812 KB Output is correct
9 Correct 12 ms 25908 KB Output is correct
10 Correct 12 ms 25812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 25908 KB Output is correct
2 Correct 12 ms 25884 KB Output is correct
3 Correct 360 ms 101184 KB Output is correct
4 Correct 359 ms 111344 KB Output is correct
5 Correct 408 ms 127460 KB Output is correct
6 Correct 535 ms 149056 KB Output is correct
7 Correct 663 ms 172684 KB Output is correct
8 Correct 619 ms 172616 KB Output is correct
9 Correct 638 ms 172608 KB Output is correct
10 Correct 11 ms 25812 KB Output is correct
11 Correct 11 ms 25804 KB Output is correct
12 Correct 10 ms 25836 KB Output is correct
13 Correct 14 ms 25812 KB Output is correct
14 Correct 12 ms 25940 KB Output is correct
15 Correct 12 ms 25940 KB Output is correct
16 Correct 14 ms 25940 KB Output is correct
17 Correct 12 ms 25812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 25812 KB Output is correct
2 Correct 11 ms 25912 KB Output is correct
3 Correct 13 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 12 ms 25812 KB Output is correct
6 Correct 11 ms 25812 KB Output is correct
7 Correct 11 ms 25892 KB Output is correct
8 Correct 11 ms 25812 KB Output is correct
9 Correct 12 ms 25908 KB Output is correct
10 Correct 12 ms 25812 KB Output is correct
11 Correct 10 ms 25940 KB Output is correct
12 Correct 12 ms 25908 KB Output is correct
13 Correct 12 ms 26004 KB Output is correct
14 Correct 10 ms 25940 KB Output is correct
15 Correct 11 ms 26044 KB Output is correct
16 Correct 11 ms 25940 KB Output is correct
17 Correct 12 ms 25884 KB Output is correct
18 Correct 11 ms 25812 KB Output is correct
19 Correct 14 ms 25940 KB Output is correct
20 Correct 11 ms 25864 KB Output is correct
21 Correct 14 ms 25940 KB Output is correct
22 Correct 15 ms 26068 KB Output is correct
23 Correct 11 ms 26068 KB Output is correct
24 Correct 12 ms 26124 KB Output is correct
25 Correct 12 ms 26068 KB Output is correct
26 Correct 14 ms 26196 KB Output is correct
27 Correct 11 ms 26068 KB Output is correct
28 Correct 11 ms 26000 KB Output is correct
29 Correct 12 ms 26132 KB Output is correct
30 Correct 11 ms 26068 KB Output is correct
31 Correct 10 ms 26068 KB Output is correct
32 Correct 12 ms 26148 KB Output is correct
33 Correct 12 ms 26068 KB Output is correct
34 Correct 12 ms 25780 KB Output is correct
35 Correct 11 ms 25812 KB Output is correct
36 Correct 12 ms 25912 KB Output is correct
37 Correct 12 ms 25940 KB Output is correct
38 Correct 13 ms 25908 KB Output is correct
39 Correct 14 ms 26012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 25812 KB Output is correct
2 Correct 11 ms 25912 KB Output is correct
3 Correct 13 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 12 ms 25812 KB Output is correct
6 Correct 11 ms 25812 KB Output is correct
7 Correct 11 ms 25892 KB Output is correct
8 Correct 11 ms 25812 KB Output is correct
9 Correct 12 ms 25908 KB Output is correct
10 Correct 12 ms 25812 KB Output is correct
11 Correct 10 ms 25940 KB Output is correct
12 Correct 12 ms 25908 KB Output is correct
13 Correct 12 ms 26004 KB Output is correct
14 Correct 10 ms 25940 KB Output is correct
15 Correct 11 ms 26044 KB Output is correct
16 Correct 11 ms 25940 KB Output is correct
17 Correct 12 ms 25884 KB Output is correct
18 Correct 11 ms 25812 KB Output is correct
19 Correct 14 ms 25940 KB Output is correct
20 Correct 11 ms 25864 KB Output is correct
21 Correct 14 ms 25940 KB Output is correct
22 Correct 15 ms 26068 KB Output is correct
23 Correct 11 ms 26068 KB Output is correct
24 Correct 12 ms 26124 KB Output is correct
25 Correct 12 ms 26068 KB Output is correct
26 Correct 14 ms 26196 KB Output is correct
27 Correct 11 ms 26068 KB Output is correct
28 Correct 11 ms 26000 KB Output is correct
29 Correct 12 ms 26132 KB Output is correct
30 Correct 11 ms 26068 KB Output is correct
31 Correct 10 ms 26068 KB Output is correct
32 Correct 12 ms 26148 KB Output is correct
33 Correct 12 ms 26068 KB Output is correct
34 Correct 12 ms 25780 KB Output is correct
35 Correct 11 ms 25812 KB Output is correct
36 Correct 12 ms 25912 KB Output is correct
37 Correct 12 ms 25940 KB Output is correct
38 Correct 13 ms 25908 KB Output is correct
39 Correct 14 ms 26012 KB Output is correct
40 Correct 16 ms 27396 KB Output is correct
41 Correct 16 ms 27452 KB Output is correct
42 Correct 18 ms 33672 KB Output is correct
43 Correct 19 ms 33860 KB Output is correct
44 Correct 19 ms 33876 KB Output is correct
45 Correct 18 ms 34004 KB Output is correct
46 Correct 18 ms 34008 KB Output is correct
47 Correct 16 ms 28900 KB Output is correct
48 Correct 17 ms 31444 KB Output is correct
49 Correct 19 ms 32368 KB Output is correct
50 Correct 19 ms 32444 KB Output is correct
51 Correct 20 ms 30936 KB Output is correct
52 Correct 24 ms 30924 KB Output is correct
53 Correct 19 ms 34004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 25812 KB Output is correct
2 Correct 11 ms 25912 KB Output is correct
3 Correct 13 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 12 ms 25812 KB Output is correct
6 Correct 11 ms 25812 KB Output is correct
7 Correct 11 ms 25892 KB Output is correct
8 Correct 11 ms 25812 KB Output is correct
9 Correct 12 ms 25908 KB Output is correct
10 Correct 12 ms 25812 KB Output is correct
11 Correct 10 ms 25940 KB Output is correct
12 Correct 12 ms 25908 KB Output is correct
13 Correct 12 ms 26004 KB Output is correct
14 Correct 10 ms 25940 KB Output is correct
15 Correct 11 ms 26044 KB Output is correct
16 Correct 11 ms 25940 KB Output is correct
17 Correct 12 ms 25884 KB Output is correct
18 Correct 11 ms 25812 KB Output is correct
19 Correct 14 ms 25940 KB Output is correct
20 Correct 11 ms 25864 KB Output is correct
21 Correct 14 ms 25940 KB Output is correct
22 Correct 15 ms 26068 KB Output is correct
23 Correct 11 ms 26068 KB Output is correct
24 Correct 12 ms 26124 KB Output is correct
25 Correct 12 ms 26068 KB Output is correct
26 Correct 14 ms 26196 KB Output is correct
27 Correct 11 ms 26068 KB Output is correct
28 Correct 11 ms 26000 KB Output is correct
29 Correct 12 ms 26132 KB Output is correct
30 Correct 11 ms 26068 KB Output is correct
31 Correct 10 ms 26068 KB Output is correct
32 Correct 12 ms 26148 KB Output is correct
33 Correct 12 ms 26068 KB Output is correct
34 Correct 12 ms 25780 KB Output is correct
35 Correct 11 ms 25812 KB Output is correct
36 Correct 12 ms 25912 KB Output is correct
37 Correct 12 ms 25940 KB Output is correct
38 Correct 13 ms 25908 KB Output is correct
39 Correct 14 ms 26012 KB Output is correct
40 Correct 16 ms 27396 KB Output is correct
41 Correct 16 ms 27452 KB Output is correct
42 Correct 18 ms 33672 KB Output is correct
43 Correct 19 ms 33860 KB Output is correct
44 Correct 19 ms 33876 KB Output is correct
45 Correct 18 ms 34004 KB Output is correct
46 Correct 18 ms 34008 KB Output is correct
47 Correct 16 ms 28900 KB Output is correct
48 Correct 17 ms 31444 KB Output is correct
49 Correct 19 ms 32368 KB Output is correct
50 Correct 19 ms 32444 KB Output is correct
51 Correct 20 ms 30936 KB Output is correct
52 Correct 24 ms 30924 KB Output is correct
53 Correct 19 ms 34004 KB Output is correct
54 Correct 49 ms 63460 KB Output is correct
55 Correct 88 ms 48660 KB Output is correct
56 Correct 229 ms 211164 KB Output is correct
57 Correct 232 ms 212300 KB Output is correct
58 Correct 211 ms 213300 KB Output is correct
59 Correct 223 ms 213456 KB Output is correct
60 Correct 207 ms 213652 KB Output is correct
61 Correct 206 ms 121932 KB Output is correct
62 Correct 91 ms 49516 KB Output is correct
63 Correct 201 ms 173808 KB Output is correct
64 Correct 246 ms 174100 KB Output is correct
65 Correct 304 ms 130328 KB Output is correct
66 Correct 316 ms 130312 KB Output is correct
67 Correct 201 ms 213620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 25812 KB Output is correct
2 Correct 11 ms 25912 KB Output is correct
3 Correct 13 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 12 ms 25812 KB Output is correct
6 Correct 11 ms 25812 KB Output is correct
7 Correct 11 ms 25892 KB Output is correct
8 Correct 11 ms 25812 KB Output is correct
9 Correct 12 ms 25908 KB Output is correct
10 Correct 12 ms 25812 KB Output is correct
11 Correct 15 ms 25908 KB Output is correct
12 Correct 12 ms 25884 KB Output is correct
13 Correct 360 ms 101184 KB Output is correct
14 Correct 359 ms 111344 KB Output is correct
15 Correct 408 ms 127460 KB Output is correct
16 Correct 535 ms 149056 KB Output is correct
17 Correct 663 ms 172684 KB Output is correct
18 Correct 619 ms 172616 KB Output is correct
19 Correct 638 ms 172608 KB Output is correct
20 Correct 11 ms 25812 KB Output is correct
21 Correct 11 ms 25804 KB Output is correct
22 Correct 10 ms 25836 KB Output is correct
23 Correct 14 ms 25812 KB Output is correct
24 Correct 12 ms 25940 KB Output is correct
25 Correct 12 ms 25940 KB Output is correct
26 Correct 14 ms 25940 KB Output is correct
27 Correct 12 ms 25812 KB Output is correct
28 Correct 10 ms 25940 KB Output is correct
29 Correct 12 ms 25908 KB Output is correct
30 Correct 12 ms 26004 KB Output is correct
31 Correct 10 ms 25940 KB Output is correct
32 Correct 11 ms 26044 KB Output is correct
33 Correct 11 ms 25940 KB Output is correct
34 Correct 12 ms 25884 KB Output is correct
35 Correct 11 ms 25812 KB Output is correct
36 Correct 14 ms 25940 KB Output is correct
37 Correct 11 ms 25864 KB Output is correct
38 Correct 14 ms 25940 KB Output is correct
39 Correct 15 ms 26068 KB Output is correct
40 Correct 11 ms 26068 KB Output is correct
41 Correct 12 ms 26124 KB Output is correct
42 Correct 12 ms 26068 KB Output is correct
43 Correct 14 ms 26196 KB Output is correct
44 Correct 11 ms 26068 KB Output is correct
45 Correct 11 ms 26000 KB Output is correct
46 Correct 12 ms 26132 KB Output is correct
47 Correct 11 ms 26068 KB Output is correct
48 Correct 10 ms 26068 KB Output is correct
49 Correct 12 ms 26148 KB Output is correct
50 Correct 12 ms 26068 KB Output is correct
51 Correct 12 ms 25780 KB Output is correct
52 Correct 11 ms 25812 KB Output is correct
53 Correct 12 ms 25912 KB Output is correct
54 Correct 12 ms 25940 KB Output is correct
55 Correct 13 ms 25908 KB Output is correct
56 Correct 14 ms 26012 KB Output is correct
57 Correct 16 ms 27396 KB Output is correct
58 Correct 16 ms 27452 KB Output is correct
59 Correct 18 ms 33672 KB Output is correct
60 Correct 19 ms 33860 KB Output is correct
61 Correct 19 ms 33876 KB Output is correct
62 Correct 18 ms 34004 KB Output is correct
63 Correct 18 ms 34008 KB Output is correct
64 Correct 16 ms 28900 KB Output is correct
65 Correct 17 ms 31444 KB Output is correct
66 Correct 19 ms 32368 KB Output is correct
67 Correct 19 ms 32444 KB Output is correct
68 Correct 20 ms 30936 KB Output is correct
69 Correct 24 ms 30924 KB Output is correct
70 Correct 19 ms 34004 KB Output is correct
71 Correct 49 ms 63460 KB Output is correct
72 Correct 88 ms 48660 KB Output is correct
73 Correct 229 ms 211164 KB Output is correct
74 Correct 232 ms 212300 KB Output is correct
75 Correct 211 ms 213300 KB Output is correct
76 Correct 223 ms 213456 KB Output is correct
77 Correct 207 ms 213652 KB Output is correct
78 Correct 206 ms 121932 KB Output is correct
79 Correct 91 ms 49516 KB Output is correct
80 Correct 201 ms 173808 KB Output is correct
81 Correct 246 ms 174100 KB Output is correct
82 Correct 304 ms 130328 KB Output is correct
83 Correct 316 ms 130312 KB Output is correct
84 Correct 201 ms 213620 KB Output is correct
85 Correct 453 ms 487476 KB Output is correct
86 Correct 1291 ms 1177088 KB Output is correct
87 Correct 1277 ms 1180328 KB Output is correct
88 Correct 1213 ms 1182384 KB Output is correct
89 Correct 1240 ms 1183384 KB Output is correct
90 Correct 1213 ms 1183848 KB Output is correct
91 Correct 1505 ms 193132 KB Output is correct
92 Correct 1183 ms 155820 KB Output is correct
93 Correct 1664 ms 886432 KB Output is correct
94 Correct 1570 ms 930484 KB Output is correct
95 Execution timed out 3107 ms 656580 KB Time limit exceeded
96 Halted 0 ms 0 KB -