답안 #896061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896061 2023-12-31T15:10:35 Z alexander707070 Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
2268 ms 223992 KB
#include<bits/stdc++.h>
#define MAXN 2507
using namespace std;
 
const long long inf=1e15;
const long long mod=1000000000100011;
 
int n,len;
long long a,b,c,curr;
char s[MAXN];
 
long long dp[MAXN][MAXN];
bool li[MAXN][MAXN];
long long hesh,power;
int nxt[MAXN][MAXN];

long long cost(long long len,long long cnt,long long sz){
    return (len-cnt*sz)*a+cnt*c;
}

unordered_map<long long, vector<int> > last;
unordered_map<long long, int > pt; 

void calc_dp(){
    for(int i=1;i<=n;i++){
        for(int f=1;f<=n;f++){
            dp[i][f]=inf;
        }
    }

    for(int len=1;len<=n;len++){
        for(int s=1;s+len-1<=n;s++){
            int l=s,r=s+len-1;

            if(len==1)dp[l][r]=a;

            dp[l-1][r]=min(dp[l-1][r],dp[l][r]+a);
            dp[l][r+1]=min(dp[l][r+1],dp[l][r]+a);

            long long cnt=0;

            for(int k=s;k<=n;k=nxt[k][k+len-1]){
                cnt++;
                dp[l][k+len-1]=min(dp[l][k+len-1],dp[l][r]+cost(k+len-1-l+1,cnt,r-l+1)+b );
            }
        }
    }
}

 
int main(){
 
    cin>>n>>(s+1);
    cin>>a>>b>>c;

    power=1;
    for(int len=1;len<=n;len++){

        last.clear(); hesh=0;
        for(int t=n;t>=n-len+1;t--){
            hesh*=26; hesh+=s[t]-'a'; hesh%=mod;
        }
        power*=26; power%=mod;

        for(int t=n-len+1;t>=1;t--){

            if(!last[hesh].empty()){

                while(pt[hesh]+1<last[hesh].size() and last[hesh][pt[hesh]+1]>t+len-1){
                    pt[hesh]++;
                }

                if(pt[hesh]!=-1){
                    nxt[t][t+len-1]=last[hesh][pt[hesh]];
                }else{
                    nxt[t][t+len-1]=n+1;
                }
            }else{
                nxt[t][t+len-1]=n+1;
                pt[hesh]=-1;
            }

            last[hesh].push_back(t);

            hesh*=26; hesh+=s[t-1]-'a'; hesh%=mod;

            hesh-=(long long) ((s[t+len-1]-'a')*power)%mod;
            hesh+=mod; hesh%=mod;
        }
    }

    calc_dp();
 
    cout<<dp[1][n]<<"\n";
 
    return 0;
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:69:33: warning: comparison of integer expressions of different signedness: 'std::unordered_map<long long int, int>::mapped_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |                 while(pt[hesh]+1<last[hesh].size() and last[hesh][pt[hesh]+1]>t+len-1){
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4884 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4560 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 227 ms 60212 KB Output is correct
4 Correct 287 ms 64052 KB Output is correct
5 Correct 366 ms 70548 KB Output is correct
6 Correct 397 ms 74492 KB Output is correct
7 Correct 473 ms 76372 KB Output is correct
8 Correct 484 ms 76140 KB Output is correct
9 Correct 482 ms 76112 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 6688 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4884 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4560 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 6496 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8536 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
33 Correct 1 ms 8536 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4884 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4560 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 6496 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8536 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
33 Correct 1 ms 8536 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 8540 KB Output is correct
40 Correct 2 ms 8792 KB Output is correct
41 Correct 4 ms 10584 KB Output is correct
42 Correct 6 ms 11356 KB Output is correct
43 Correct 5 ms 11356 KB Output is correct
44 Correct 5 ms 11356 KB Output is correct
45 Correct 5 ms 11436 KB Output is correct
46 Correct 6 ms 11360 KB Output is correct
47 Correct 5 ms 10844 KB Output is correct
48 Correct 5 ms 11356 KB Output is correct
49 Correct 5 ms 11356 KB Output is correct
50 Correct 5 ms 11356 KB Output is correct
51 Correct 5 ms 11356 KB Output is correct
52 Correct 5 ms 11356 KB Output is correct
53 Correct 5 ms 11356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4884 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4560 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 6496 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8536 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
33 Correct 1 ms 8536 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 8540 KB Output is correct
40 Correct 2 ms 8792 KB Output is correct
41 Correct 4 ms 10584 KB Output is correct
42 Correct 6 ms 11356 KB Output is correct
43 Correct 5 ms 11356 KB Output is correct
44 Correct 5 ms 11356 KB Output is correct
45 Correct 5 ms 11436 KB Output is correct
46 Correct 6 ms 11360 KB Output is correct
47 Correct 5 ms 10844 KB Output is correct
48 Correct 5 ms 11356 KB Output is correct
49 Correct 5 ms 11356 KB Output is correct
50 Correct 5 ms 11356 KB Output is correct
51 Correct 5 ms 11356 KB Output is correct
52 Correct 5 ms 11356 KB Output is correct
53 Correct 5 ms 11356 KB Output is correct
54 Correct 25 ms 25292 KB Output is correct
55 Correct 85 ms 35480 KB Output is correct
56 Correct 185 ms 56732 KB Output is correct
57 Correct 154 ms 56576 KB Output is correct
58 Correct 155 ms 56768 KB Output is correct
59 Correct 165 ms 55624 KB Output is correct
60 Correct 151 ms 56564 KB Output is correct
61 Correct 119 ms 44416 KB Output is correct
62 Correct 85 ms 35576 KB Output is correct
63 Correct 143 ms 52136 KB Output is correct
64 Correct 137 ms 52676 KB Output is correct
65 Correct 117 ms 45764 KB Output is correct
66 Correct 117 ms 45696 KB Output is correct
67 Correct 152 ms 56224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4884 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4560 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 227 ms 60212 KB Output is correct
14 Correct 287 ms 64052 KB Output is correct
15 Correct 366 ms 70548 KB Output is correct
16 Correct 397 ms 74492 KB Output is correct
17 Correct 473 ms 76372 KB Output is correct
18 Correct 484 ms 76140 KB Output is correct
19 Correct 482 ms 76112 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 6688 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 1 ms 6496 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 8540 KB Output is correct
39 Correct 1 ms 8540 KB Output is correct
40 Correct 1 ms 8540 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 8536 KB Output is correct
43 Correct 1 ms 8540 KB Output is correct
44 Correct 1 ms 8540 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 8536 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 2 ms 8792 KB Output is correct
58 Correct 4 ms 10584 KB Output is correct
59 Correct 6 ms 11356 KB Output is correct
60 Correct 5 ms 11356 KB Output is correct
61 Correct 5 ms 11356 KB Output is correct
62 Correct 5 ms 11436 KB Output is correct
63 Correct 6 ms 11360 KB Output is correct
64 Correct 5 ms 10844 KB Output is correct
65 Correct 5 ms 11356 KB Output is correct
66 Correct 5 ms 11356 KB Output is correct
67 Correct 5 ms 11356 KB Output is correct
68 Correct 5 ms 11356 KB Output is correct
69 Correct 5 ms 11356 KB Output is correct
70 Correct 5 ms 11356 KB Output is correct
71 Correct 25 ms 25292 KB Output is correct
72 Correct 85 ms 35480 KB Output is correct
73 Correct 185 ms 56732 KB Output is correct
74 Correct 154 ms 56576 KB Output is correct
75 Correct 155 ms 56768 KB Output is correct
76 Correct 165 ms 55624 KB Output is correct
77 Correct 151 ms 56564 KB Output is correct
78 Correct 119 ms 44416 KB Output is correct
79 Correct 85 ms 35576 KB Output is correct
80 Correct 143 ms 52136 KB Output is correct
81 Correct 137 ms 52676 KB Output is correct
82 Correct 117 ms 45764 KB Output is correct
83 Correct 117 ms 45696 KB Output is correct
84 Correct 152 ms 56224 KB Output is correct
85 Correct 594 ms 104696 KB Output is correct
86 Correct 2268 ms 223040 KB Output is correct
87 Correct 2169 ms 223456 KB Output is correct
88 Correct 2181 ms 223992 KB Output is correct
89 Correct 2238 ms 223912 KB Output is correct
90 Correct 2139 ms 219972 KB Output is correct
91 Correct 574 ms 82396 KB Output is correct
92 Correct 658 ms 77228 KB Output is correct
93 Correct 1450 ms 165948 KB Output is correct
94 Correct 1516 ms 172236 KB Output is correct
95 Correct 1358 ms 146908 KB Output is correct
96 Correct 1347 ms 146796 KB Output is correct
97 Correct 2142 ms 220204 KB Output is correct