Submission #872545

# Submission time Handle Problem Language Result Execution time Memory
872545 2023-11-13T10:48:34 Z mrwang Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
1411 ms 325012 KB
#include<bits/stdc++.h>
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxn=2e5;
const ll inf=1e18;
const ll mod=1e15+37;
ll f[maxn]={0};
ll a,b,c;
vector<pli>g[2506][2506];
void dfs(ll x,ll y,ll h,ll v)
{
    ll j=x+y-1;
    f[j]=min(f[j],-y*h*a+c*h+b+v);
    for(auto zz:g[x][y])
    {
        dfs(zz.fi,zz.se,h+1,v);
    }
}
ll mu(ll a, ll b) {
    ll k = (ll)((long double)a * b / mod);
    ll r = a * b - mod * k;
    if (r < 0) r += mod;
    if (r >= mod) r -= mod;
    return r;
}
string s;
ll hs[maxn],n,pw[maxn];
ll base=311;
ll get(ll i,ll j)
{
    return (hs[j]-mu(hs[i-1],pw[j-i+1]) + mod) %mod;
}
struct qq
{
    ll v,l,r;
    bool operator<(const qq&o)
    {
        if(v==o.v) return l<o.l;
        return v<o.v;
    }
};
ll dp[2506][2506];
vector<qq> vec;
void solve()
{
    cin >> n >> s >> a >> b >> c;
    s=' '+s;
    pw[0]=1;
    for(int i=1;i<=n;i++)
    {
        hs[i]=(hs[i-1]*base+s[i])%mod;
        pw[i]=pw[i-1]*base%mod;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            vec.pb({get(i,j),i,j});
        }
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<vec.size();i++)
    {
        ll j=i;
        vector<ll> pos;
        while(j<vec.size()&&vec[i].v==vec[j].v)
        {
            pos.pb(vec[j].l);
            j++;
        }
        ll len=vec[i].r-vec[i].l+1;
        for(int q=pos.size()-1;q>=0;q--)
        {
            ll u=pos[q];
            ll x=upper_bound(pos.begin(),pos.end(),u-len)-pos.begin()-1;
            if(x>=0)
            {
                ll v=pos[x];
                g[v][len].pb({u,len});
            }
        }
        i=j-1;
    }
    for(int i=n;i>=1;i--)
    {
        for(int j=i;j<=n;j++)
        {
            if(i==j) dp[i][j]=a;
            else
            {
                dp[i][j]=dp[i][j-1]+a;
                dp[i][j]=min(dp[i][j],(j-i+1)*a+f[j]);
            }
            dfs(i,j-i+1,1,dp[i][j]);
        }
    }
    cout << dp[1][n];
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

copypaste3.cpp: In function 'void solve()':
copypaste3.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<qq>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i=0;i<vec.size();i++)
      |                 ~^~~~~~~~~~~
copypaste3.cpp:71:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<qq>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         while(j<vec.size()&&vec[i].v==vec[j].v)
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 154192 KB Output is correct
2 Correct 33 ms 154200 KB Output is correct
3 Correct 34 ms 154292 KB Output is correct
4 Correct 34 ms 154204 KB Output is correct
5 Correct 36 ms 154204 KB Output is correct
6 Correct 38 ms 154272 KB Output is correct
7 Correct 33 ms 154200 KB Output is correct
8 Correct 33 ms 154596 KB Output is correct
9 Correct 36 ms 154316 KB Output is correct
10 Correct 34 ms 154280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 156252 KB Output is correct
2 Correct 34 ms 154196 KB Output is correct
3 Correct 688 ms 257812 KB Output is correct
4 Correct 859 ms 270272 KB Output is correct
5 Correct 1018 ms 287744 KB Output is correct
6 Correct 1195 ms 307128 KB Output is correct
7 Correct 1411 ms 324832 KB Output is correct
8 Correct 1374 ms 324336 KB Output is correct
9 Correct 1384 ms 325012 KB Output is correct
10 Correct 36 ms 154492 KB Output is correct
11 Correct 34 ms 154200 KB Output is correct
12 Correct 34 ms 154204 KB Output is correct
13 Correct 35 ms 154300 KB Output is correct
14 Correct 36 ms 154372 KB Output is correct
15 Correct 36 ms 156248 KB Output is correct
16 Correct 34 ms 156240 KB Output is correct
17 Correct 36 ms 154200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 154192 KB Output is correct
2 Correct 33 ms 154200 KB Output is correct
3 Correct 34 ms 154292 KB Output is correct
4 Correct 34 ms 154204 KB Output is correct
5 Correct 36 ms 154204 KB Output is correct
6 Correct 38 ms 154272 KB Output is correct
7 Correct 33 ms 154200 KB Output is correct
8 Correct 33 ms 154596 KB Output is correct
9 Correct 36 ms 154316 KB Output is correct
10 Correct 34 ms 154280 KB Output is correct
11 Correct 35 ms 156344 KB Output is correct
12 Correct 38 ms 156252 KB Output is correct
13 Correct 36 ms 156452 KB Output is correct
14 Correct 35 ms 154164 KB Output is correct
15 Correct 33 ms 156400 KB Output is correct
16 Correct 36 ms 156452 KB Output is correct
17 Correct 35 ms 154196 KB Output is correct
18 Correct 34 ms 154152 KB Output is correct
19 Correct 34 ms 156280 KB Output is correct
20 Correct 35 ms 154376 KB Output is correct
21 Correct 35 ms 156452 KB Output is correct
22 Correct 36 ms 156244 KB Output is correct
23 Correct 35 ms 156276 KB Output is correct
24 Correct 34 ms 156244 KB Output is correct
25 Correct 34 ms 156252 KB Output is correct
26 Correct 35 ms 156452 KB Output is correct
27 Correct 36 ms 156252 KB Output is correct
28 Correct 35 ms 156288 KB Output is correct
29 Correct 39 ms 156452 KB Output is correct
30 Correct 37 ms 156252 KB Output is correct
31 Correct 34 ms 156324 KB Output is correct
32 Correct 35 ms 156464 KB Output is correct
33 Correct 37 ms 156264 KB Output is correct
34 Correct 34 ms 154308 KB Output is correct
35 Correct 37 ms 154268 KB Output is correct
36 Correct 35 ms 154352 KB Output is correct
37 Correct 35 ms 154148 KB Output is correct
38 Correct 35 ms 156252 KB Output is correct
39 Correct 37 ms 156316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 154192 KB Output is correct
2 Correct 33 ms 154200 KB Output is correct
3 Correct 34 ms 154292 KB Output is correct
4 Correct 34 ms 154204 KB Output is correct
5 Correct 36 ms 154204 KB Output is correct
6 Correct 38 ms 154272 KB Output is correct
7 Correct 33 ms 154200 KB Output is correct
8 Correct 33 ms 154596 KB Output is correct
9 Correct 36 ms 154316 KB Output is correct
10 Correct 34 ms 154280 KB Output is correct
11 Correct 35 ms 156344 KB Output is correct
12 Correct 38 ms 156252 KB Output is correct
13 Correct 36 ms 156452 KB Output is correct
14 Correct 35 ms 154164 KB Output is correct
15 Correct 33 ms 156400 KB Output is correct
16 Correct 36 ms 156452 KB Output is correct
17 Correct 35 ms 154196 KB Output is correct
18 Correct 34 ms 154152 KB Output is correct
19 Correct 34 ms 156280 KB Output is correct
20 Correct 35 ms 154376 KB Output is correct
21 Correct 35 ms 156452 KB Output is correct
22 Correct 36 ms 156244 KB Output is correct
23 Correct 35 ms 156276 KB Output is correct
24 Correct 34 ms 156244 KB Output is correct
25 Correct 34 ms 156252 KB Output is correct
26 Correct 35 ms 156452 KB Output is correct
27 Correct 36 ms 156252 KB Output is correct
28 Correct 35 ms 156288 KB Output is correct
29 Correct 39 ms 156452 KB Output is correct
30 Correct 37 ms 156252 KB Output is correct
31 Correct 34 ms 156324 KB Output is correct
32 Correct 35 ms 156464 KB Output is correct
33 Correct 37 ms 156264 KB Output is correct
34 Correct 34 ms 154308 KB Output is correct
35 Correct 37 ms 154268 KB Output is correct
36 Correct 35 ms 154352 KB Output is correct
37 Correct 35 ms 154148 KB Output is correct
38 Correct 35 ms 156252 KB Output is correct
39 Correct 37 ms 156316 KB Output is correct
40 Correct 38 ms 156508 KB Output is correct
41 Correct 40 ms 159180 KB Output is correct
42 Correct 39 ms 158888 KB Output is correct
43 Correct 39 ms 158928 KB Output is correct
44 Correct 40 ms 159012 KB Output is correct
45 Correct 39 ms 158932 KB Output is correct
46 Correct 38 ms 158992 KB Output is correct
47 Correct 40 ms 159088 KB Output is correct
48 Correct 38 ms 159180 KB Output is correct
49 Correct 38 ms 158940 KB Output is correct
50 Correct 39 ms 159032 KB Output is correct
51 Correct 43 ms 159184 KB Output is correct
52 Correct 45 ms 159204 KB Output is correct
53 Correct 41 ms 158932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 154192 KB Output is correct
2 Correct 33 ms 154200 KB Output is correct
3 Correct 34 ms 154292 KB Output is correct
4 Correct 34 ms 154204 KB Output is correct
5 Correct 36 ms 154204 KB Output is correct
6 Correct 38 ms 154272 KB Output is correct
7 Correct 33 ms 154200 KB Output is correct
8 Correct 33 ms 154596 KB Output is correct
9 Correct 36 ms 154316 KB Output is correct
10 Correct 34 ms 154280 KB Output is correct
11 Correct 35 ms 156344 KB Output is correct
12 Correct 38 ms 156252 KB Output is correct
13 Correct 36 ms 156452 KB Output is correct
14 Correct 35 ms 154164 KB Output is correct
15 Correct 33 ms 156400 KB Output is correct
16 Correct 36 ms 156452 KB Output is correct
17 Correct 35 ms 154196 KB Output is correct
18 Correct 34 ms 154152 KB Output is correct
19 Correct 34 ms 156280 KB Output is correct
20 Correct 35 ms 154376 KB Output is correct
21 Correct 35 ms 156452 KB Output is correct
22 Correct 36 ms 156244 KB Output is correct
23 Correct 35 ms 156276 KB Output is correct
24 Correct 34 ms 156244 KB Output is correct
25 Correct 34 ms 156252 KB Output is correct
26 Correct 35 ms 156452 KB Output is correct
27 Correct 36 ms 156252 KB Output is correct
28 Correct 35 ms 156288 KB Output is correct
29 Correct 39 ms 156452 KB Output is correct
30 Correct 37 ms 156252 KB Output is correct
31 Correct 34 ms 156324 KB Output is correct
32 Correct 35 ms 156464 KB Output is correct
33 Correct 37 ms 156264 KB Output is correct
34 Correct 34 ms 154308 KB Output is correct
35 Correct 37 ms 154268 KB Output is correct
36 Correct 35 ms 154352 KB Output is correct
37 Correct 35 ms 154148 KB Output is correct
38 Correct 35 ms 156252 KB Output is correct
39 Correct 37 ms 156316 KB Output is correct
40 Correct 38 ms 156508 KB Output is correct
41 Correct 40 ms 159180 KB Output is correct
42 Correct 39 ms 158888 KB Output is correct
43 Correct 39 ms 158928 KB Output is correct
44 Correct 40 ms 159012 KB Output is correct
45 Correct 39 ms 158932 KB Output is correct
46 Correct 38 ms 158992 KB Output is correct
47 Correct 40 ms 159088 KB Output is correct
48 Correct 38 ms 159180 KB Output is correct
49 Correct 38 ms 158940 KB Output is correct
50 Correct 39 ms 159032 KB Output is correct
51 Correct 43 ms 159184 KB Output is correct
52 Correct 45 ms 159204 KB Output is correct
53 Correct 41 ms 158932 KB Output is correct
54 Correct 49 ms 167368 KB Output is correct
55 Correct 191 ms 194448 KB Output is correct
56 Correct 104 ms 187308 KB Output is correct
57 Correct 99 ms 186808 KB Output is correct
58 Correct 103 ms 187052 KB Output is correct
59 Correct 98 ms 186796 KB Output is correct
60 Correct 95 ms 186796 KB Output is correct
61 Correct 142 ms 192688 KB Output is correct
62 Correct 154 ms 194404 KB Output is correct
63 Correct 123 ms 190636 KB Output is correct
64 Correct 130 ms 190888 KB Output is correct
65 Correct 146 ms 192180 KB Output is correct
66 Correct 145 ms 192300 KB Output is correct
67 Correct 107 ms 186716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 154192 KB Output is correct
2 Correct 33 ms 154200 KB Output is correct
3 Correct 34 ms 154292 KB Output is correct
4 Correct 34 ms 154204 KB Output is correct
5 Correct 36 ms 154204 KB Output is correct
6 Correct 38 ms 154272 KB Output is correct
7 Correct 33 ms 154200 KB Output is correct
8 Correct 33 ms 154596 KB Output is correct
9 Correct 36 ms 154316 KB Output is correct
10 Correct 34 ms 154280 KB Output is correct
11 Correct 34 ms 156252 KB Output is correct
12 Correct 34 ms 154196 KB Output is correct
13 Correct 688 ms 257812 KB Output is correct
14 Correct 859 ms 270272 KB Output is correct
15 Correct 1018 ms 287744 KB Output is correct
16 Correct 1195 ms 307128 KB Output is correct
17 Correct 1411 ms 324832 KB Output is correct
18 Correct 1374 ms 324336 KB Output is correct
19 Correct 1384 ms 325012 KB Output is correct
20 Correct 36 ms 154492 KB Output is correct
21 Correct 34 ms 154200 KB Output is correct
22 Correct 34 ms 154204 KB Output is correct
23 Correct 35 ms 154300 KB Output is correct
24 Correct 36 ms 154372 KB Output is correct
25 Correct 36 ms 156248 KB Output is correct
26 Correct 34 ms 156240 KB Output is correct
27 Correct 36 ms 154200 KB Output is correct
28 Correct 35 ms 156344 KB Output is correct
29 Correct 38 ms 156252 KB Output is correct
30 Correct 36 ms 156452 KB Output is correct
31 Correct 35 ms 154164 KB Output is correct
32 Correct 33 ms 156400 KB Output is correct
33 Correct 36 ms 156452 KB Output is correct
34 Correct 35 ms 154196 KB Output is correct
35 Correct 34 ms 154152 KB Output is correct
36 Correct 34 ms 156280 KB Output is correct
37 Correct 35 ms 154376 KB Output is correct
38 Correct 35 ms 156452 KB Output is correct
39 Correct 36 ms 156244 KB Output is correct
40 Correct 35 ms 156276 KB Output is correct
41 Correct 34 ms 156244 KB Output is correct
42 Correct 34 ms 156252 KB Output is correct
43 Correct 35 ms 156452 KB Output is correct
44 Correct 36 ms 156252 KB Output is correct
45 Correct 35 ms 156288 KB Output is correct
46 Correct 39 ms 156452 KB Output is correct
47 Correct 37 ms 156252 KB Output is correct
48 Correct 34 ms 156324 KB Output is correct
49 Correct 35 ms 156464 KB Output is correct
50 Correct 37 ms 156264 KB Output is correct
51 Correct 34 ms 154308 KB Output is correct
52 Correct 37 ms 154268 KB Output is correct
53 Correct 35 ms 154352 KB Output is correct
54 Correct 35 ms 154148 KB Output is correct
55 Correct 35 ms 156252 KB Output is correct
56 Correct 37 ms 156316 KB Output is correct
57 Correct 38 ms 156508 KB Output is correct
58 Correct 40 ms 159180 KB Output is correct
59 Correct 39 ms 158888 KB Output is correct
60 Correct 39 ms 158928 KB Output is correct
61 Correct 40 ms 159012 KB Output is correct
62 Correct 39 ms 158932 KB Output is correct
63 Correct 38 ms 158992 KB Output is correct
64 Correct 40 ms 159088 KB Output is correct
65 Correct 38 ms 159180 KB Output is correct
66 Correct 38 ms 158940 KB Output is correct
67 Correct 39 ms 159032 KB Output is correct
68 Correct 43 ms 159184 KB Output is correct
69 Correct 45 ms 159204 KB Output is correct
70 Correct 41 ms 158932 KB Output is correct
71 Correct 49 ms 167368 KB Output is correct
72 Correct 191 ms 194448 KB Output is correct
73 Correct 104 ms 187308 KB Output is correct
74 Correct 99 ms 186808 KB Output is correct
75 Correct 103 ms 187052 KB Output is correct
76 Correct 98 ms 186796 KB Output is correct
77 Correct 95 ms 186796 KB Output is correct
78 Correct 142 ms 192688 KB Output is correct
79 Correct 154 ms 194404 KB Output is correct
80 Correct 123 ms 190636 KB Output is correct
81 Correct 130 ms 190888 KB Output is correct
82 Correct 146 ms 192180 KB Output is correct
83 Correct 145 ms 192300 KB Output is correct
84 Correct 107 ms 186716 KB Output is correct
85 Correct 214 ms 217756 KB Output is correct
86 Correct 523 ms 275940 KB Output is correct
87 Correct 478 ms 275844 KB Output is correct
88 Correct 467 ms 275488 KB Output is correct
89 Correct 460 ms 276440 KB Output is correct
90 Correct 453 ms 276264 KB Output is correct
91 Correct 1220 ms 323620 KB Output is correct
92 Correct 1309 ms 324980 KB Output is correct
93 Correct 754 ms 305496 KB Output is correct
94 Correct 708 ms 300436 KB Output is correct
95 Correct 1012 ms 313484 KB Output is correct
96 Correct 1016 ms 312988 KB Output is correct
97 Correct 458 ms 276504 KB Output is correct