Submission #1061133

# Submission time Handle Problem Language Result Execution time Memory
1061133 2024-08-16T06:32:10 Z ttamx Copy and Paste 3 (JOI22_copypaste3) C++17
6 / 100
156 ms 73188 KB
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

const int N=2505;

int n;
string s;
ll a,b,c;
int nxt[N][N];
ll dp[N][N];

vector<int> z_algo(const string &s){
    int n=s.size();
    vector<int> z(n);
    z[0]=n;
    for(int i=1,l=0,r=1;i<n;i++){
        if(i<r)z[i]=min(r-i,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]])z[i]++;
        if(i+z[i]>r)l=r,r=i+z[i];
    }
    return z;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    cin >> s;
    cin >> a >> b >> c;
    for(int l=0;l<n;l++){
        auto z=z_algo(s.substr(l,n-l));
        int p=l;
        for(int r=l;r<n;r++){
            while(p<n&&(p<=r||z[p-l]<r-l+1))p++;
            nxt[l][r]=p;
        }
    }
    for(int l=0;l<n;l++){
        for(int r=l;r<n;r++){
            dp[l][r]=(r-l+1)*a;
        }
    }
    for(int sz=1;sz<=n;sz++){
        for(int l=0,r=sz-1;r<n;l++,r++){
            if(l>0)dp[l-1][r]=min(dp[l-1][r],dp[l][r]+a);
            if(r+1<n)dp[l][r+1]=min(dp[l][r+1],dp[l][r]+a);
            int p=nxt[l][r];
            int cnt=2;
            while(p<n){
                dp[l][p+sz-1]=min(dp[l][p+sz-1],dp[l][r]+(p+sz-l-sz*cnt)*a+b+cnt*c);
                p=nxt[p][p+sz-1];
                cnt++;
            }
        }
    }
    cout << dp[0][n-1] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 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 66 ms 58092 KB Output is correct
4 Correct 83 ms 62044 KB Output is correct
5 Correct 91 ms 68188 KB Output is correct
6 Correct 116 ms 70236 KB Output is correct
7 Correct 156 ms 73052 KB Output is correct
8 Correct 156 ms 73044 KB Output is correct
9 Correct 138 ms 73188 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 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 Incorrect 1 ms 4444 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 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 Incorrect 1 ms 4444 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 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 Incorrect 1 ms 4444 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 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 66 ms 58092 KB Output is correct
14 Correct 83 ms 62044 KB Output is correct
15 Correct 91 ms 68188 KB Output is correct
16 Correct 116 ms 70236 KB Output is correct
17 Correct 156 ms 73052 KB Output is correct
18 Correct 156 ms 73044 KB Output is correct
19 Correct 138 ms 73188 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 0 ms 2392 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Incorrect 1 ms 4444 KB Output isn't correct
31 Halted 0 ms 0 KB -