답안 #567799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567799 2022-05-24T08:28:00 Z tqbfjotld Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
3000 ms 100860 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];

inline 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;
        pt[x][x] = 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;
        }
    }
    pt[n][n] = rt;
    rt->constructall();
    mem[rt->nid] = 0;
    for (int x = 1; x<=n; x++){
        for (int y = 0; x+y<=n; y++){
            int a = y;
            int b = x+y;
            //printf("a b %d %d\n",a,b);
            long long ans = mem[pt[a+1][b]->nid]+A;
            for (int x = 1; x<b-a; x++){
                long long t = mem[pt[a][a+x]->nid];
                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);
            mem[pt[a][b]->nid] = ans;
        }
    }
    printf("%lld",mem[pt[0][n]->nid]);
}

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:82:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   82 | main(){
      | ^~~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
copypaste3.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         scanf(" %c",&arr[x]);
      |         ~~~~~^~~~~~~~~~~~~~~
copypaste3.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |     scanf("%lld%lld%lld",&A,&B,&C);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25812 KB Output is correct
2 Correct 11 ms 25864 KB Output is correct
3 Correct 10 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 13 ms 25860 KB Output is correct
6 Correct 10 ms 25812 KB Output is correct
7 Correct 12 ms 25812 KB Output is correct
8 Correct 13 ms 25796 KB Output is correct
9 Correct 11 ms 25804 KB Output is correct
10 Correct 10 ms 25812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 25888 KB Output is correct
2 Correct 11 ms 25812 KB Output is correct
3 Execution timed out 3068 ms 100860 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25812 KB Output is correct
2 Correct 11 ms 25864 KB Output is correct
3 Correct 10 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 13 ms 25860 KB Output is correct
6 Correct 10 ms 25812 KB Output is correct
7 Correct 12 ms 25812 KB Output is correct
8 Correct 13 ms 25796 KB Output is correct
9 Correct 11 ms 25804 KB Output is correct
10 Correct 10 ms 25812 KB Output is correct
11 Correct 11 ms 25860 KB Output is correct
12 Correct 13 ms 25940 KB Output is correct
13 Correct 13 ms 25920 KB Output is correct
14 Correct 11 ms 25940 KB Output is correct
15 Correct 11 ms 25992 KB Output is correct
16 Correct 10 ms 25940 KB Output is correct
17 Correct 11 ms 25884 KB Output is correct
18 Correct 11 ms 25812 KB Output is correct
19 Correct 11 ms 25940 KB Output is correct
20 Correct 10 ms 25812 KB Output is correct
21 Correct 11 ms 25940 KB Output is correct
22 Correct 11 ms 26100 KB Output is correct
23 Correct 11 ms 26068 KB Output is correct
24 Correct 11 ms 26172 KB Output is correct
25 Correct 11 ms 26160 KB Output is correct
26 Correct 10 ms 26132 KB Output is correct
27 Correct 11 ms 26060 KB Output is correct
28 Correct 11 ms 26068 KB Output is correct
29 Correct 11 ms 26068 KB Output is correct
30 Correct 11 ms 26088 KB Output is correct
31 Correct 11 ms 26068 KB Output is correct
32 Correct 11 ms 26068 KB Output is correct
33 Correct 12 ms 26196 KB Output is correct
34 Correct 12 ms 25896 KB Output is correct
35 Correct 12 ms 25812 KB Output is correct
36 Correct 12 ms 25848 KB Output is correct
37 Correct 11 ms 25940 KB Output is correct
38 Correct 10 ms 25940 KB Output is correct
39 Correct 12 ms 26024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25812 KB Output is correct
2 Correct 11 ms 25864 KB Output is correct
3 Correct 10 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 13 ms 25860 KB Output is correct
6 Correct 10 ms 25812 KB Output is correct
7 Correct 12 ms 25812 KB Output is correct
8 Correct 13 ms 25796 KB Output is correct
9 Correct 11 ms 25804 KB Output is correct
10 Correct 10 ms 25812 KB Output is correct
11 Correct 11 ms 25860 KB Output is correct
12 Correct 13 ms 25940 KB Output is correct
13 Correct 13 ms 25920 KB Output is correct
14 Correct 11 ms 25940 KB Output is correct
15 Correct 11 ms 25992 KB Output is correct
16 Correct 10 ms 25940 KB Output is correct
17 Correct 11 ms 25884 KB Output is correct
18 Correct 11 ms 25812 KB Output is correct
19 Correct 11 ms 25940 KB Output is correct
20 Correct 10 ms 25812 KB Output is correct
21 Correct 11 ms 25940 KB Output is correct
22 Correct 11 ms 26100 KB Output is correct
23 Correct 11 ms 26068 KB Output is correct
24 Correct 11 ms 26172 KB Output is correct
25 Correct 11 ms 26160 KB Output is correct
26 Correct 10 ms 26132 KB Output is correct
27 Correct 11 ms 26060 KB Output is correct
28 Correct 11 ms 26068 KB Output is correct
29 Correct 11 ms 26068 KB Output is correct
30 Correct 11 ms 26088 KB Output is correct
31 Correct 11 ms 26068 KB Output is correct
32 Correct 11 ms 26068 KB Output is correct
33 Correct 12 ms 26196 KB Output is correct
34 Correct 12 ms 25896 KB Output is correct
35 Correct 12 ms 25812 KB Output is correct
36 Correct 12 ms 25848 KB Output is correct
37 Correct 11 ms 25940 KB Output is correct
38 Correct 10 ms 25940 KB Output is correct
39 Correct 12 ms 26024 KB Output is correct
40 Correct 13 ms 27348 KB Output is correct
41 Correct 64 ms 27452 KB Output is correct
42 Correct 26 ms 33688 KB Output is correct
43 Correct 23 ms 33804 KB Output is correct
44 Correct 20 ms 33876 KB Output is correct
45 Correct 28 ms 33952 KB Output is correct
46 Correct 24 ms 33924 KB Output is correct
47 Correct 28 ms 28884 KB Output is correct
48 Correct 23 ms 31360 KB Output is correct
49 Correct 24 ms 32332 KB Output is correct
50 Correct 26 ms 32348 KB Output is correct
51 Correct 32 ms 30836 KB Output is correct
52 Correct 31 ms 30980 KB Output is correct
53 Correct 20 ms 34004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25812 KB Output is correct
2 Correct 11 ms 25864 KB Output is correct
3 Correct 10 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 13 ms 25860 KB Output is correct
6 Correct 10 ms 25812 KB Output is correct
7 Correct 12 ms 25812 KB Output is correct
8 Correct 13 ms 25796 KB Output is correct
9 Correct 11 ms 25804 KB Output is correct
10 Correct 10 ms 25812 KB Output is correct
11 Correct 11 ms 25860 KB Output is correct
12 Correct 13 ms 25940 KB Output is correct
13 Correct 13 ms 25920 KB Output is correct
14 Correct 11 ms 25940 KB Output is correct
15 Correct 11 ms 25992 KB Output is correct
16 Correct 10 ms 25940 KB Output is correct
17 Correct 11 ms 25884 KB Output is correct
18 Correct 11 ms 25812 KB Output is correct
19 Correct 11 ms 25940 KB Output is correct
20 Correct 10 ms 25812 KB Output is correct
21 Correct 11 ms 25940 KB Output is correct
22 Correct 11 ms 26100 KB Output is correct
23 Correct 11 ms 26068 KB Output is correct
24 Correct 11 ms 26172 KB Output is correct
25 Correct 11 ms 26160 KB Output is correct
26 Correct 10 ms 26132 KB Output is correct
27 Correct 11 ms 26060 KB Output is correct
28 Correct 11 ms 26068 KB Output is correct
29 Correct 11 ms 26068 KB Output is correct
30 Correct 11 ms 26088 KB Output is correct
31 Correct 11 ms 26068 KB Output is correct
32 Correct 11 ms 26068 KB Output is correct
33 Correct 12 ms 26196 KB Output is correct
34 Correct 12 ms 25896 KB Output is correct
35 Correct 12 ms 25812 KB Output is correct
36 Correct 12 ms 25848 KB Output is correct
37 Correct 11 ms 25940 KB Output is correct
38 Correct 10 ms 25940 KB Output is correct
39 Correct 12 ms 26024 KB Output is correct
40 Correct 13 ms 27348 KB Output is correct
41 Correct 64 ms 27452 KB Output is correct
42 Correct 26 ms 33688 KB Output is correct
43 Correct 23 ms 33804 KB Output is correct
44 Correct 20 ms 33876 KB Output is correct
45 Correct 28 ms 33952 KB Output is correct
46 Correct 24 ms 33924 KB Output is correct
47 Correct 28 ms 28884 KB Output is correct
48 Correct 23 ms 31360 KB Output is correct
49 Correct 24 ms 32332 KB Output is correct
50 Correct 26 ms 32348 KB Output is correct
51 Correct 32 ms 30836 KB Output is correct
52 Correct 31 ms 30980 KB Output is correct
53 Correct 20 ms 34004 KB Output is correct
54 Correct 129 ms 63412 KB Output is correct
55 Execution timed out 3071 ms 48588 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25812 KB Output is correct
2 Correct 11 ms 25864 KB Output is correct
3 Correct 10 ms 25812 KB Output is correct
4 Correct 10 ms 25812 KB Output is correct
5 Correct 13 ms 25860 KB Output is correct
6 Correct 10 ms 25812 KB Output is correct
7 Correct 12 ms 25812 KB Output is correct
8 Correct 13 ms 25796 KB Output is correct
9 Correct 11 ms 25804 KB Output is correct
10 Correct 10 ms 25812 KB Output is correct
11 Correct 11 ms 25888 KB Output is correct
12 Correct 11 ms 25812 KB Output is correct
13 Execution timed out 3068 ms 100860 KB Time limit exceeded
14 Halted 0 ms 0 KB -