Submission #1060968

# Submission time Handle Problem Language Result Execution time Memory
1060968 2024-08-16T05:05:52 Z 12345678 Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
741 ms 836508 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define int long long

const ll nx=2505, mod=1e9+7, mul=31;

ll n, a, b, c, s[nx], dp[nx][nx], pw[nx];
string stmp;

struct update
{
    ll l, r, cnta, cntc;
    update(ll l=0, ll r=0, ll cnta=0, ll cntc=0): l(l), r(r), cnta(cnta), cntc(cntc){}
};
vector<update> calc[nx][nx];

int32_t main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>stmp>>a>>b>>c;
    pw[0]=1;
    for (int i=1; i<=n; i++) s[i]=stmp[i-1]-'a'+1, pw[i]=(pw[i-1]*mul)%mod;
    for (int sz=1; sz<=n; sz++)
    {
        map<ll, vector<ll>> mp;
        ll sm=0;
        for (int i=1; i<=sz; i++) sm=(sm+pw[sz-i]*s[i])%mod;
        mp[sm].push_back(1);
        for (int i=sz+1; i<=n; i++) sm=(sm*mul)%mod, sm=((sm-s[i-sz]*pw[sz])%mod+mod)%mod, sm=(sm+s[i])%mod, mp[sm].push_back(i-sz+1);
        for (auto &[_, v]:mp)
        {
            int csz=v.size(), pts=v.size();
            vector<int> pa(csz);
            for (int i=csz-1; i>=0; i--)
            {
                while (pts!=0&&v[i]+sz<=v[pts-1]) pts--;
                if (pts!=v.size()) pa[i]=pts;
                else pa[i]=-1; 
            }
            /*
            cout<<"string update ";
            for (int i=v[0]; i<v[0]+sz; i++) cout<<(char)(s[i]-1+'a');
            cout<<'\n';
            for (int i=0; i<csz; i++) cout<<pa[i]<<' ';
            cout<<'\n';*/
            for (int i=0; i<csz; i++)
            {
                if (pa[i]==-1) continue;
                ll tmp=pa[i], cnt=2;
                while (tmp!=-1) 
                {
                    calc[v[0]][v[0]+sz-1].push_back(update(v[i], v[tmp]+sz-1, v[tmp]+sz-v[i]-cnt*sz, cnt));
                    //cout<<"upd "<<v[i]<<' '<<v[tmp]+sz-1<<' '<<v[tmp]+sz-v[i]-cnt*sz<<' '<<cnt<<'\n';
                    cnt++;
                    tmp=pa[tmp];
                }
            }
        }
    }
    for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j]=1e18;
    for (int i=1; i<=n; i++) dp[i][i]=a;
    for (int sz=0; sz<=n; sz++)
    {
        for (int l=1; l+sz<=n; l++)
        {
            int r=l+sz;
            if (l!=r) dp[l][r]=min({dp[l][r], dp[l+1][r]+a, dp[l][r-1]+a});
            for (auto upd:calc[l][r]) dp[upd.l][upd.r]=min(dp[upd.l][upd.r], dp[l][r]+c*upd.cntc+a*upd.cnta+b);
            //cout<<"dp "<<l<<' '<<r<<' '<<dp[l][r]<<'\n';
        }
    }
    cout<<dp[1][n];
}

Compilation message

copypaste3.cpp: In function 'int32_t main()':
copypaste3.cpp:40:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |                 if (pts!=v.size()) pa[i]=pts;
      |                     ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 148304 KB Output is correct
2 Correct 42 ms 148304 KB Output is correct
3 Correct 39 ms 148316 KB Output is correct
4 Correct 37 ms 148356 KB Output is correct
5 Correct 39 ms 148312 KB Output is correct
6 Correct 42 ms 148352 KB Output is correct
7 Correct 38 ms 148308 KB Output is correct
8 Correct 36 ms 148108 KB Output is correct
9 Correct 37 ms 148308 KB Output is correct
10 Correct 37 ms 148304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 148316 KB Output is correct
2 Correct 38 ms 148304 KB Output is correct
3 Correct 369 ms 508744 KB Output is correct
4 Correct 433 ms 572892 KB Output is correct
5 Correct 530 ms 647232 KB Output is correct
6 Correct 623 ms 733832 KB Output is correct
7 Correct 741 ms 836488 KB Output is correct
8 Correct 730 ms 836360 KB Output is correct
9 Correct 727 ms 836508 KB Output is correct
10 Correct 36 ms 148308 KB Output is correct
11 Correct 37 ms 148316 KB Output is correct
12 Correct 40 ms 148284 KB Output is correct
13 Correct 41 ms 148308 KB Output is correct
14 Correct 39 ms 148348 KB Output is correct
15 Correct 41 ms 148308 KB Output is correct
16 Correct 39 ms 148356 KB Output is correct
17 Correct 41 ms 148308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 148304 KB Output is correct
2 Correct 42 ms 148304 KB Output is correct
3 Correct 39 ms 148316 KB Output is correct
4 Correct 37 ms 148356 KB Output is correct
5 Correct 39 ms 148312 KB Output is correct
6 Correct 42 ms 148352 KB Output is correct
7 Correct 38 ms 148308 KB Output is correct
8 Correct 36 ms 148108 KB Output is correct
9 Correct 37 ms 148308 KB Output is correct
10 Correct 37 ms 148304 KB Output is correct
11 Correct 39 ms 148304 KB Output is correct
12 Correct 40 ms 148316 KB Output is correct
13 Correct 40 ms 148304 KB Output is correct
14 Correct 42 ms 148304 KB Output is correct
15 Correct 43 ms 148316 KB Output is correct
16 Correct 40 ms 148136 KB Output is correct
17 Correct 40 ms 148304 KB Output is correct
18 Correct 45 ms 148304 KB Output is correct
19 Correct 40 ms 148316 KB Output is correct
20 Correct 38 ms 148308 KB Output is correct
21 Correct 41 ms 148312 KB Output is correct
22 Correct 39 ms 148384 KB Output is correct
23 Correct 45 ms 148308 KB Output is correct
24 Correct 38 ms 148304 KB Output is correct
25 Correct 37 ms 148316 KB Output is correct
26 Correct 38 ms 148308 KB Output is correct
27 Correct 40 ms 148308 KB Output is correct
28 Correct 40 ms 148384 KB Output is correct
29 Correct 39 ms 148312 KB Output is correct
30 Correct 42 ms 148304 KB Output is correct
31 Correct 41 ms 148308 KB Output is correct
32 Correct 40 ms 148308 KB Output is correct
33 Correct 41 ms 148300 KB Output is correct
34 Correct 39 ms 148308 KB Output is correct
35 Correct 40 ms 148312 KB Output is correct
36 Correct 38 ms 148248 KB Output is correct
37 Correct 37 ms 148316 KB Output is correct
38 Correct 39 ms 148316 KB Output is correct
39 Correct 42 ms 148308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 148304 KB Output is correct
2 Correct 42 ms 148304 KB Output is correct
3 Correct 39 ms 148316 KB Output is correct
4 Correct 37 ms 148356 KB Output is correct
5 Correct 39 ms 148312 KB Output is correct
6 Correct 42 ms 148352 KB Output is correct
7 Correct 38 ms 148308 KB Output is correct
8 Correct 36 ms 148108 KB Output is correct
9 Correct 37 ms 148308 KB Output is correct
10 Correct 37 ms 148304 KB Output is correct
11 Correct 39 ms 148304 KB Output is correct
12 Correct 40 ms 148316 KB Output is correct
13 Correct 40 ms 148304 KB Output is correct
14 Correct 42 ms 148304 KB Output is correct
15 Correct 43 ms 148316 KB Output is correct
16 Correct 40 ms 148136 KB Output is correct
17 Correct 40 ms 148304 KB Output is correct
18 Correct 45 ms 148304 KB Output is correct
19 Correct 40 ms 148316 KB Output is correct
20 Correct 38 ms 148308 KB Output is correct
21 Correct 41 ms 148312 KB Output is correct
22 Correct 39 ms 148384 KB Output is correct
23 Correct 45 ms 148308 KB Output is correct
24 Correct 38 ms 148304 KB Output is correct
25 Correct 37 ms 148316 KB Output is correct
26 Correct 38 ms 148308 KB Output is correct
27 Correct 40 ms 148308 KB Output is correct
28 Correct 40 ms 148384 KB Output is correct
29 Correct 39 ms 148312 KB Output is correct
30 Correct 42 ms 148304 KB Output is correct
31 Correct 41 ms 148308 KB Output is correct
32 Correct 40 ms 148308 KB Output is correct
33 Correct 41 ms 148300 KB Output is correct
34 Correct 39 ms 148308 KB Output is correct
35 Correct 40 ms 148312 KB Output is correct
36 Correct 38 ms 148248 KB Output is correct
37 Correct 37 ms 148316 KB Output is correct
38 Correct 39 ms 148316 KB Output is correct
39 Correct 42 ms 148308 KB Output is correct
40 Correct 39 ms 148560 KB Output is correct
41 Correct 45 ms 152020 KB Output is correct
42 Correct 43 ms 149924 KB Output is correct
43 Correct 41 ms 149692 KB Output is correct
44 Correct 42 ms 149332 KB Output is correct
45 Correct 42 ms 149332 KB Output is correct
46 Correct 41 ms 149332 KB Output is correct
47 Correct 43 ms 150152 KB Output is correct
48 Correct 44 ms 149584 KB Output is correct
49 Correct 44 ms 149692 KB Output is correct
50 Correct 43 ms 149584 KB Output is correct
51 Correct 46 ms 150612 KB Output is correct
52 Correct 42 ms 150616 KB Output is correct
53 Correct 42 ms 149232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 148304 KB Output is correct
2 Correct 42 ms 148304 KB Output is correct
3 Correct 39 ms 148316 KB Output is correct
4 Correct 37 ms 148356 KB Output is correct
5 Correct 39 ms 148312 KB Output is correct
6 Correct 42 ms 148352 KB Output is correct
7 Correct 38 ms 148308 KB Output is correct
8 Correct 36 ms 148108 KB Output is correct
9 Correct 37 ms 148308 KB Output is correct
10 Correct 37 ms 148304 KB Output is correct
11 Correct 39 ms 148304 KB Output is correct
12 Correct 40 ms 148316 KB Output is correct
13 Correct 40 ms 148304 KB Output is correct
14 Correct 42 ms 148304 KB Output is correct
15 Correct 43 ms 148316 KB Output is correct
16 Correct 40 ms 148136 KB Output is correct
17 Correct 40 ms 148304 KB Output is correct
18 Correct 45 ms 148304 KB Output is correct
19 Correct 40 ms 148316 KB Output is correct
20 Correct 38 ms 148308 KB Output is correct
21 Correct 41 ms 148312 KB Output is correct
22 Correct 39 ms 148384 KB Output is correct
23 Correct 45 ms 148308 KB Output is correct
24 Correct 38 ms 148304 KB Output is correct
25 Correct 37 ms 148316 KB Output is correct
26 Correct 38 ms 148308 KB Output is correct
27 Correct 40 ms 148308 KB Output is correct
28 Correct 40 ms 148384 KB Output is correct
29 Correct 39 ms 148312 KB Output is correct
30 Correct 42 ms 148304 KB Output is correct
31 Correct 41 ms 148308 KB Output is correct
32 Correct 40 ms 148308 KB Output is correct
33 Correct 41 ms 148300 KB Output is correct
34 Correct 39 ms 148308 KB Output is correct
35 Correct 40 ms 148312 KB Output is correct
36 Correct 38 ms 148248 KB Output is correct
37 Correct 37 ms 148316 KB Output is correct
38 Correct 39 ms 148316 KB Output is correct
39 Correct 42 ms 148308 KB Output is correct
40 Correct 39 ms 148560 KB Output is correct
41 Correct 45 ms 152020 KB Output is correct
42 Correct 43 ms 149924 KB Output is correct
43 Correct 41 ms 149692 KB Output is correct
44 Correct 42 ms 149332 KB Output is correct
45 Correct 42 ms 149332 KB Output is correct
46 Correct 41 ms 149332 KB Output is correct
47 Correct 43 ms 150152 KB Output is correct
48 Correct 44 ms 149584 KB Output is correct
49 Correct 44 ms 149692 KB Output is correct
50 Correct 43 ms 149584 KB Output is correct
51 Correct 46 ms 150612 KB Output is correct
52 Correct 42 ms 150616 KB Output is correct
53 Correct 42 ms 149232 KB Output is correct
54 Correct 59 ms 154652 KB Output is correct
55 Correct 128 ms 248992 KB Output is correct
56 Correct 139 ms 174896 KB Output is correct
57 Correct 129 ms 167740 KB Output is correct
58 Correct 127 ms 163252 KB Output is correct
59 Correct 124 ms 161232 KB Output is correct
60 Correct 121 ms 160596 KB Output is correct
61 Correct 123 ms 175184 KB Output is correct
62 Correct 117 ms 233416 KB Output is correct
63 Correct 153 ms 171348 KB Output is correct
64 Correct 140 ms 177332 KB Output is correct
65 Correct 142 ms 206552 KB Output is correct
66 Correct 155 ms 214956 KB Output is correct
67 Correct 132 ms 169556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 148304 KB Output is correct
2 Correct 42 ms 148304 KB Output is correct
3 Correct 39 ms 148316 KB Output is correct
4 Correct 37 ms 148356 KB Output is correct
5 Correct 39 ms 148312 KB Output is correct
6 Correct 42 ms 148352 KB Output is correct
7 Correct 38 ms 148308 KB Output is correct
8 Correct 36 ms 148108 KB Output is correct
9 Correct 37 ms 148308 KB Output is correct
10 Correct 37 ms 148304 KB Output is correct
11 Correct 36 ms 148316 KB Output is correct
12 Correct 38 ms 148304 KB Output is correct
13 Correct 369 ms 508744 KB Output is correct
14 Correct 433 ms 572892 KB Output is correct
15 Correct 530 ms 647232 KB Output is correct
16 Correct 623 ms 733832 KB Output is correct
17 Correct 741 ms 836488 KB Output is correct
18 Correct 730 ms 836360 KB Output is correct
19 Correct 727 ms 836508 KB Output is correct
20 Correct 36 ms 148308 KB Output is correct
21 Correct 37 ms 148316 KB Output is correct
22 Correct 40 ms 148284 KB Output is correct
23 Correct 41 ms 148308 KB Output is correct
24 Correct 39 ms 148348 KB Output is correct
25 Correct 41 ms 148308 KB Output is correct
26 Correct 39 ms 148356 KB Output is correct
27 Correct 41 ms 148308 KB Output is correct
28 Correct 39 ms 148304 KB Output is correct
29 Correct 40 ms 148316 KB Output is correct
30 Correct 40 ms 148304 KB Output is correct
31 Correct 42 ms 148304 KB Output is correct
32 Correct 43 ms 148316 KB Output is correct
33 Correct 40 ms 148136 KB Output is correct
34 Correct 40 ms 148304 KB Output is correct
35 Correct 45 ms 148304 KB Output is correct
36 Correct 40 ms 148316 KB Output is correct
37 Correct 38 ms 148308 KB Output is correct
38 Correct 41 ms 148312 KB Output is correct
39 Correct 39 ms 148384 KB Output is correct
40 Correct 45 ms 148308 KB Output is correct
41 Correct 38 ms 148304 KB Output is correct
42 Correct 37 ms 148316 KB Output is correct
43 Correct 38 ms 148308 KB Output is correct
44 Correct 40 ms 148308 KB Output is correct
45 Correct 40 ms 148384 KB Output is correct
46 Correct 39 ms 148312 KB Output is correct
47 Correct 42 ms 148304 KB Output is correct
48 Correct 41 ms 148308 KB Output is correct
49 Correct 40 ms 148308 KB Output is correct
50 Correct 41 ms 148300 KB Output is correct
51 Correct 39 ms 148308 KB Output is correct
52 Correct 40 ms 148312 KB Output is correct
53 Correct 38 ms 148248 KB Output is correct
54 Correct 37 ms 148316 KB Output is correct
55 Correct 39 ms 148316 KB Output is correct
56 Correct 42 ms 148308 KB Output is correct
57 Correct 39 ms 148560 KB Output is correct
58 Correct 45 ms 152020 KB Output is correct
59 Correct 43 ms 149924 KB Output is correct
60 Correct 41 ms 149692 KB Output is correct
61 Correct 42 ms 149332 KB Output is correct
62 Correct 42 ms 149332 KB Output is correct
63 Correct 41 ms 149332 KB Output is correct
64 Correct 43 ms 150152 KB Output is correct
65 Correct 44 ms 149584 KB Output is correct
66 Correct 44 ms 149692 KB Output is correct
67 Correct 43 ms 149584 KB Output is correct
68 Correct 46 ms 150612 KB Output is correct
69 Correct 42 ms 150616 KB Output is correct
70 Correct 42 ms 149232 KB Output is correct
71 Correct 59 ms 154652 KB Output is correct
72 Correct 128 ms 248992 KB Output is correct
73 Correct 139 ms 174896 KB Output is correct
74 Correct 129 ms 167740 KB Output is correct
75 Correct 127 ms 163252 KB Output is correct
76 Correct 124 ms 161232 KB Output is correct
77 Correct 121 ms 160596 KB Output is correct
78 Correct 123 ms 175184 KB Output is correct
79 Correct 117 ms 233416 KB Output is correct
80 Correct 153 ms 171348 KB Output is correct
81 Correct 140 ms 177332 KB Output is correct
82 Correct 142 ms 206552 KB Output is correct
83 Correct 155 ms 214956 KB Output is correct
84 Correct 132 ms 169556 KB Output is correct
85 Correct 299 ms 212232 KB Output is correct
86 Correct 714 ms 291204 KB Output is correct
87 Correct 708 ms 247928 KB Output is correct
88 Correct 642 ms 216956 KB Output is correct
89 Correct 638 ms 205336 KB Output is correct
90 Incorrect 707 ms 201092 KB Output isn't correct
91 Halted 0 ms 0 KB -