Submission #872633

# Submission time Handle Problem Language Result Execution time Memory
872633 2023-11-13T13:18:49 Z winter0101 Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
3000 ms 73044 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int maxn=2509;
int n;
string s;
long long x,y,z;
long long f[maxn][maxn];
int lcp[maxn][maxn];
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    cin>>n>>s>>x>>y>>z;
    s=" "+s;
    for1(i,1,n){
    for1(j,1,n){
    lcp[i][j]=lcp[i-1][j-1]-1;
    if (lcp[i-1][j-1]==0)lcp[i][j]=0;
    while (lcp[i][j]<=n-max(j,i)+1&&s[i+lcp[i][j]]==s[j+lcp[i][j]]){
    lcp[i][j]++;
    }
    }
    }
    for1(i,1,n){
    for1(j,i,n){
    f[i][j]=1ll*(j-i+1)*x;
    }
    }
    for1(len,1,n){
    for1(i,1,n-len+1){
    int j=i+len-1;
    if (i>1)f[i-1][j]=min(f[i-1][j],f[i][j]+x);
    if (j+1<=n)f[i][j+1]=min(f[i][j+1],f[i][j]+x);
    long long cost=y+z+f[i][j];
    for1(p,j+1,n){
    if (lcp[p][i]>=len){
    cost+=z;
    p+=len-1;
    }
    else {
    cost+=x;
    }
    f[i][p]=min(f[i][p],cost);
    }
    }
    }
    cout<<f[1][n];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 667 ms 58076 KB Output is correct
4 Correct 813 ms 62176 KB Output is correct
5 Correct 1046 ms 68336 KB Output is correct
6 Correct 1323 ms 72528 KB Output is correct
7 Correct 1673 ms 73040 KB Output is correct
8 Correct 1655 ms 73044 KB Output is correct
9 Correct 1663 ms 72836 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 6536 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6496 KB Output is correct
25 Correct 1 ms 6496 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6612 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6496 KB Output is correct
25 Correct 1 ms 6496 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6612 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6488 KB Output is correct
41 Correct 2 ms 8536 KB Output is correct
42 Correct 4 ms 8536 KB Output is correct
43 Correct 3 ms 8536 KB Output is correct
44 Correct 3 ms 8540 KB Output is correct
45 Correct 3 ms 8788 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8540 KB Output is correct
48 Correct 3 ms 8760 KB Output is correct
49 Correct 3 ms 8536 KB Output is correct
50 Correct 3 ms 8792 KB Output is correct
51 Correct 3 ms 8536 KB Output is correct
52 Correct 3 ms 8536 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6496 KB Output is correct
25 Correct 1 ms 6496 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6612 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6488 KB Output is correct
41 Correct 2 ms 8536 KB Output is correct
42 Correct 4 ms 8536 KB Output is correct
43 Correct 3 ms 8536 KB Output is correct
44 Correct 3 ms 8540 KB Output is correct
45 Correct 3 ms 8788 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8540 KB Output is correct
48 Correct 3 ms 8760 KB Output is correct
49 Correct 3 ms 8536 KB Output is correct
50 Correct 3 ms 8792 KB Output is correct
51 Correct 3 ms 8536 KB Output is correct
52 Correct 3 ms 8536 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
54 Correct 25 ms 18780 KB Output is correct
55 Correct 100 ms 33412 KB Output is correct
56 Correct 248 ms 33416 KB Output is correct
57 Correct 251 ms 33412 KB Output is correct
58 Correct 243 ms 33416 KB Output is correct
59 Correct 244 ms 33616 KB Output is correct
60 Correct 236 ms 33408 KB Output is correct
61 Correct 185 ms 33416 KB Output is correct
62 Correct 105 ms 33368 KB Output is correct
63 Correct 214 ms 33408 KB Output is correct
64 Correct 207 ms 33412 KB Output is correct
65 Correct 169 ms 33368 KB Output is correct
66 Correct 163 ms 33368 KB Output is correct
67 Correct 242 ms 33408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 667 ms 58076 KB Output is correct
14 Correct 813 ms 62176 KB Output is correct
15 Correct 1046 ms 68336 KB Output is correct
16 Correct 1323 ms 72528 KB Output is correct
17 Correct 1673 ms 73040 KB Output is correct
18 Correct 1655 ms 73044 KB Output is correct
19 Correct 1663 ms 72836 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 6536 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 6488 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 6496 KB Output is correct
42 Correct 1 ms 6496 KB Output is correct
43 Correct 1 ms 6748 KB Output is correct
44 Correct 1 ms 6612 KB Output is correct
45 Correct 1 ms 6748 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6488 KB Output is correct
49 Correct 1 ms 6488 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 0 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 1 ms 6488 KB Output is correct
58 Correct 2 ms 8536 KB Output is correct
59 Correct 4 ms 8536 KB Output is correct
60 Correct 3 ms 8536 KB Output is correct
61 Correct 3 ms 8540 KB Output is correct
62 Correct 3 ms 8788 KB Output is correct
63 Correct 3 ms 8540 KB Output is correct
64 Correct 3 ms 8540 KB Output is correct
65 Correct 3 ms 8760 KB Output is correct
66 Correct 3 ms 8536 KB Output is correct
67 Correct 3 ms 8792 KB Output is correct
68 Correct 3 ms 8536 KB Output is correct
69 Correct 3 ms 8536 KB Output is correct
70 Correct 3 ms 8540 KB Output is correct
71 Correct 25 ms 18780 KB Output is correct
72 Correct 100 ms 33412 KB Output is correct
73 Correct 248 ms 33416 KB Output is correct
74 Correct 251 ms 33412 KB Output is correct
75 Correct 243 ms 33416 KB Output is correct
76 Correct 244 ms 33616 KB Output is correct
77 Correct 236 ms 33408 KB Output is correct
78 Correct 185 ms 33416 KB Output is correct
79 Correct 105 ms 33368 KB Output is correct
80 Correct 214 ms 33408 KB Output is correct
81 Correct 207 ms 33412 KB Output is correct
82 Correct 169 ms 33368 KB Output is correct
83 Correct 163 ms 33368 KB Output is correct
84 Correct 242 ms 33408 KB Output is correct
85 Correct 1298 ms 51916 KB Output is correct
86 Execution timed out 3058 ms 72576 KB Time limit exceeded
87 Halted 0 ms 0 KB -