Submission #927807

# Submission time Handle Problem Language Result Execution time Memory
927807 2024-02-15T10:54:20 Z andrei_boaca Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
672 ms 48720 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll INF=1e17;
ll baza=29;
const ll mod=1e9+7;
ll h[2505],A,B,C;
ll dp[2505][2505];
ll v[2505];
map<ll,ll> nrm;
vector<int> who[2505];
ll n;
string s;
ll nxt[2505];
ll pw[2505];
ll gethash(ll l,ll r)
{
    ll rez=(h[r]-(h[l-1]*pw[r-l+1])%mod+mod)%mod;
    return rez;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    pw[0]=1;
    for(int i=1;i<=2500;i++)
        pw[i]=(pw[i-1]*baza)%mod;
    cin>>n>>s>>A>>B>>C;
    s=" "+s;
    for(int i=1;i<=n;i++)
        h[i]=(h[i-1]*baza+s[i]-'a'+1)%mod;
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++)
            dp[i][j]=INF;
    for(int i=1;i<=n;i++)
        dp[i][i]=A;
    for(int lg=1;lg<n;lg++)
    {
        nrm.clear();
        vector<ll> vals;
        for(ll i=1;i+lg-1<=n;i++)
        {
            v[i]=gethash(i,i+lg-1);
            vals.push_back(v[i]);
        }
        sort(vals.begin(),vals.end());
        vals.erase(unique(vals.begin(),vals.end()),vals.end());
        for(int i=0;i<vals.size();i++)
        {
            nrm[vals[i]]=i+1;
            who[i+1].clear();
        }
        for(int i=1;i+lg-1<=n;i++)
        {
            v[i]=nrm[v[i]];
            who[v[i]].push_back(i);
        }
        for(int i=1;i+lg-1<=n;i++)
        {
            nxt[i]=n+1;
            ll st=0;
            ll dr=who[v[i]].size();
            dr--;
            while(st<=dr)
            {
                int mij=(st+dr)/2;
                if(who[v[i]][mij]>i+lg-1)
                {
                    nxt[i]=who[v[i]][mij];
                    dr=mij-1;
                }
                else
                    st=mij+1;
            }
        }
        for(int i=1;i+lg-1<=n;i++)
        {
            ll l=i;
            ll r=i+lg-1;
            if(l>1)
                dp[l-1][r]=min(dp[l-1][r],dp[l][r]+A);
            if(r<n)
                dp[l][r+1]=min(dp[l][r+1],dp[l][r]+A);
            ll val=dp[l][r];
            ll j=i;
            ll cnt=1;
            while(nxt[j]<=n)
            {
                cnt++;
                j=nxt[j];
                r=j+lg-1;
                ll cost=val+B+C*cnt+A*(r-l+1-cnt*lg);
                dp[l][r]=min(dp[l][r],cost);
            }
        }
    }
    cout<<dp[1][n];
    return 0;
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int i=0;i<vals.size();i++)
      |                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2592 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2548 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 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 200 ms 37584 KB Output is correct
4 Correct 192 ms 39640 KB Output is correct
5 Correct 232 ms 43788 KB Output is correct
6 Correct 272 ms 47704 KB Output is correct
7 Correct 329 ms 48288 KB Output is correct
8 Correct 335 ms 48304 KB Output is correct
9 Correct 372 ms 48296 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 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 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2592 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2548 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2592 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 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 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2592 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2548 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2592 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 4 ms 4444 KB Output is correct
43 Correct 3 ms 4508 KB Output is correct
44 Correct 4 ms 4696 KB Output is correct
45 Correct 4 ms 4692 KB Output is correct
46 Correct 4 ms 4696 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 3 ms 4444 KB Output is correct
49 Correct 4 ms 4440 KB Output is correct
50 Correct 4 ms 4444 KB Output is correct
51 Correct 4 ms 4444 KB Output is correct
52 Correct 3 ms 4440 KB Output is correct
53 Correct 4 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2592 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2548 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2592 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 4 ms 4444 KB Output is correct
43 Correct 3 ms 4508 KB Output is correct
44 Correct 4 ms 4696 KB Output is correct
45 Correct 4 ms 4692 KB Output is correct
46 Correct 4 ms 4696 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 3 ms 4444 KB Output is correct
49 Correct 4 ms 4440 KB Output is correct
50 Correct 4 ms 4444 KB Output is correct
51 Correct 4 ms 4444 KB Output is correct
52 Correct 3 ms 4440 KB Output is correct
53 Correct 4 ms 4700 KB Output is correct
54 Correct 17 ms 10840 KB Output is correct
55 Correct 32 ms 21084 KB Output is correct
56 Correct 97 ms 21220 KB Output is correct
57 Correct 87 ms 21220 KB Output is correct
58 Correct 97 ms 21212 KB Output is correct
59 Correct 89 ms 21212 KB Output is correct
60 Correct 95 ms 21200 KB Output is correct
61 Correct 59 ms 21144 KB Output is correct
62 Correct 36 ms 21336 KB Output is correct
63 Correct 77 ms 21080 KB Output is correct
64 Correct 80 ms 21084 KB Output is correct
65 Correct 76 ms 21432 KB Output is correct
66 Correct 61 ms 21176 KB Output is correct
67 Correct 103 ms 21204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2592 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2548 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 200 ms 37584 KB Output is correct
14 Correct 192 ms 39640 KB Output is correct
15 Correct 232 ms 43788 KB Output is correct
16 Correct 272 ms 47704 KB Output is correct
17 Correct 329 ms 48288 KB Output is correct
18 Correct 335 ms 48304 KB Output is correct
19 Correct 372 ms 48296 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2592 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2392 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 2 ms 4444 KB Output is correct
59 Correct 4 ms 4444 KB Output is correct
60 Correct 3 ms 4508 KB Output is correct
61 Correct 4 ms 4696 KB Output is correct
62 Correct 4 ms 4692 KB Output is correct
63 Correct 4 ms 4696 KB Output is correct
64 Correct 2 ms 4444 KB Output is correct
65 Correct 3 ms 4444 KB Output is correct
66 Correct 4 ms 4440 KB Output is correct
67 Correct 4 ms 4444 KB Output is correct
68 Correct 4 ms 4444 KB Output is correct
69 Correct 3 ms 4440 KB Output is correct
70 Correct 4 ms 4700 KB Output is correct
71 Correct 17 ms 10840 KB Output is correct
72 Correct 32 ms 21084 KB Output is correct
73 Correct 97 ms 21220 KB Output is correct
74 Correct 87 ms 21220 KB Output is correct
75 Correct 97 ms 21212 KB Output is correct
76 Correct 89 ms 21212 KB Output is correct
77 Correct 95 ms 21200 KB Output is correct
78 Correct 59 ms 21144 KB Output is correct
79 Correct 36 ms 21336 KB Output is correct
80 Correct 77 ms 21080 KB Output is correct
81 Correct 80 ms 21084 KB Output is correct
82 Correct 76 ms 21432 KB Output is correct
83 Correct 61 ms 21176 KB Output is correct
84 Correct 103 ms 21204 KB Output is correct
85 Correct 248 ms 33628 KB Output is correct
86 Correct 616 ms 48348 KB Output is correct
87 Correct 672 ms 48720 KB Output is correct
88 Correct 622 ms 48524 KB Output is correct
89 Correct 619 ms 48512 KB Output is correct
90 Correct 615 ms 48504 KB Output is correct
91 Correct 307 ms 48304 KB Output is correct
92 Correct 265 ms 48220 KB Output is correct
93 Correct 520 ms 48396 KB Output is correct
94 Correct 553 ms 48468 KB Output is correct
95 Correct 490 ms 48424 KB Output is correct
96 Correct 538 ms 48420 KB Output is correct
97 Incorrect 611 ms 48504 KB Output isn't correct
98 Halted 0 ms 0 KB -