Submission #872543

# Submission time Handle Problem Language Result Execution time Memory
872543 2023-11-13T10:43:20 Z mrwang Copy and Paste 3 (JOI22_copypaste3) C++14
20 / 100
1388 ms 325908 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=1e9+7;
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);
    }
}
string s;
ll hs[maxn],n,pw[maxn];
ll base=311;
ll get(ll i,ll j)
{
    return (hs[j]-(hs[i-1]*pw[j-i+1]%mod) + 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:60:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<qq>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int i=0;i<vec.size();i++)
      |                 ~^~~~~~~~~~~
copypaste3.cpp:64: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]
   64 |         while(j<vec.size()&&vec[i].v==vec[j].v)
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 45 ms 154192 KB Output is correct
2 Correct 33 ms 154196 KB Output is correct
3 Correct 33 ms 154204 KB Output is correct
4 Correct 33 ms 154200 KB Output is correct
5 Correct 34 ms 154204 KB Output is correct
6 Correct 33 ms 154204 KB Output is correct
7 Correct 33 ms 154204 KB Output is correct
8 Correct 33 ms 154376 KB Output is correct
9 Correct 33 ms 154232 KB Output is correct
10 Correct 33 ms 154204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 156252 KB Output is correct
2 Correct 33 ms 154204 KB Output is correct
3 Correct 656 ms 258240 KB Output is correct
4 Correct 751 ms 271512 KB Output is correct
5 Correct 921 ms 288396 KB Output is correct
6 Correct 1094 ms 307372 KB Output is correct
7 Correct 1388 ms 325908 KB Output is correct
8 Correct 1316 ms 325220 KB Output is correct
9 Correct 1332 ms 324576 KB Output is correct
10 Correct 33 ms 154200 KB Output is correct
11 Correct 33 ms 154192 KB Output is correct
12 Correct 35 ms 154352 KB Output is correct
13 Correct 33 ms 154292 KB Output is correct
14 Correct 34 ms 154204 KB Output is correct
15 Correct 34 ms 156408 KB Output is correct
16 Correct 36 ms 156252 KB Output is correct
17 Correct 34 ms 154348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 154192 KB Output is correct
2 Correct 33 ms 154196 KB Output is correct
3 Correct 33 ms 154204 KB Output is correct
4 Correct 33 ms 154200 KB Output is correct
5 Correct 34 ms 154204 KB Output is correct
6 Correct 33 ms 154204 KB Output is correct
7 Correct 33 ms 154204 KB Output is correct
8 Correct 33 ms 154376 KB Output is correct
9 Correct 33 ms 154232 KB Output is correct
10 Correct 33 ms 154204 KB Output is correct
11 Correct 33 ms 156244 KB Output is correct
12 Correct 37 ms 156180 KB Output is correct
13 Correct 34 ms 156208 KB Output is correct
14 Correct 33 ms 154376 KB Output is correct
15 Correct 35 ms 156244 KB Output is correct
16 Correct 33 ms 156340 KB Output is correct
17 Correct 33 ms 154200 KB Output is correct
18 Correct 33 ms 154204 KB Output is correct
19 Correct 33 ms 156252 KB Output is correct
20 Correct 33 ms 154356 KB Output is correct
21 Correct 34 ms 156456 KB Output is correct
22 Correct 34 ms 156404 KB Output is correct
23 Correct 34 ms 156244 KB Output is correct
24 Correct 34 ms 156248 KB Output is correct
25 Correct 34 ms 156252 KB Output is correct
26 Correct 34 ms 156252 KB Output is correct
27 Correct 34 ms 156252 KB Output is correct
28 Correct 33 ms 156240 KB Output is correct
29 Correct 34 ms 156600 KB Output is correct
30 Correct 34 ms 156244 KB Output is correct
31 Correct 33 ms 156452 KB Output is correct
32 Correct 35 ms 156240 KB Output is correct
33 Correct 34 ms 156240 KB Output is correct
34 Correct 33 ms 154344 KB Output is correct
35 Correct 34 ms 154192 KB Output is correct
36 Correct 34 ms 154200 KB Output is correct
37 Correct 33 ms 154156 KB Output is correct
38 Correct 33 ms 156400 KB Output is correct
39 Correct 34 ms 156448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 154192 KB Output is correct
2 Correct 33 ms 154196 KB Output is correct
3 Correct 33 ms 154204 KB Output is correct
4 Correct 33 ms 154200 KB Output is correct
5 Correct 34 ms 154204 KB Output is correct
6 Correct 33 ms 154204 KB Output is correct
7 Correct 33 ms 154204 KB Output is correct
8 Correct 33 ms 154376 KB Output is correct
9 Correct 33 ms 154232 KB Output is correct
10 Correct 33 ms 154204 KB Output is correct
11 Correct 33 ms 156244 KB Output is correct
12 Correct 37 ms 156180 KB Output is correct
13 Correct 34 ms 156208 KB Output is correct
14 Correct 33 ms 154376 KB Output is correct
15 Correct 35 ms 156244 KB Output is correct
16 Correct 33 ms 156340 KB Output is correct
17 Correct 33 ms 154200 KB Output is correct
18 Correct 33 ms 154204 KB Output is correct
19 Correct 33 ms 156252 KB Output is correct
20 Correct 33 ms 154356 KB Output is correct
21 Correct 34 ms 156456 KB Output is correct
22 Correct 34 ms 156404 KB Output is correct
23 Correct 34 ms 156244 KB Output is correct
24 Correct 34 ms 156248 KB Output is correct
25 Correct 34 ms 156252 KB Output is correct
26 Correct 34 ms 156252 KB Output is correct
27 Correct 34 ms 156252 KB Output is correct
28 Correct 33 ms 156240 KB Output is correct
29 Correct 34 ms 156600 KB Output is correct
30 Correct 34 ms 156244 KB Output is correct
31 Correct 33 ms 156452 KB Output is correct
32 Correct 35 ms 156240 KB Output is correct
33 Correct 34 ms 156240 KB Output is correct
34 Correct 33 ms 154344 KB Output is correct
35 Correct 34 ms 154192 KB Output is correct
36 Correct 34 ms 154200 KB Output is correct
37 Correct 33 ms 154156 KB Output is correct
38 Correct 33 ms 156400 KB Output is correct
39 Correct 34 ms 156448 KB Output is correct
40 Correct 35 ms 156504 KB Output is correct
41 Correct 38 ms 159192 KB Output is correct
42 Correct 38 ms 158936 KB Output is correct
43 Correct 36 ms 159036 KB Output is correct
44 Correct 37 ms 158936 KB Output is correct
45 Correct 38 ms 158936 KB Output is correct
46 Incorrect 37 ms 159060 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 154192 KB Output is correct
2 Correct 33 ms 154196 KB Output is correct
3 Correct 33 ms 154204 KB Output is correct
4 Correct 33 ms 154200 KB Output is correct
5 Correct 34 ms 154204 KB Output is correct
6 Correct 33 ms 154204 KB Output is correct
7 Correct 33 ms 154204 KB Output is correct
8 Correct 33 ms 154376 KB Output is correct
9 Correct 33 ms 154232 KB Output is correct
10 Correct 33 ms 154204 KB Output is correct
11 Correct 33 ms 156244 KB Output is correct
12 Correct 37 ms 156180 KB Output is correct
13 Correct 34 ms 156208 KB Output is correct
14 Correct 33 ms 154376 KB Output is correct
15 Correct 35 ms 156244 KB Output is correct
16 Correct 33 ms 156340 KB Output is correct
17 Correct 33 ms 154200 KB Output is correct
18 Correct 33 ms 154204 KB Output is correct
19 Correct 33 ms 156252 KB Output is correct
20 Correct 33 ms 154356 KB Output is correct
21 Correct 34 ms 156456 KB Output is correct
22 Correct 34 ms 156404 KB Output is correct
23 Correct 34 ms 156244 KB Output is correct
24 Correct 34 ms 156248 KB Output is correct
25 Correct 34 ms 156252 KB Output is correct
26 Correct 34 ms 156252 KB Output is correct
27 Correct 34 ms 156252 KB Output is correct
28 Correct 33 ms 156240 KB Output is correct
29 Correct 34 ms 156600 KB Output is correct
30 Correct 34 ms 156244 KB Output is correct
31 Correct 33 ms 156452 KB Output is correct
32 Correct 35 ms 156240 KB Output is correct
33 Correct 34 ms 156240 KB Output is correct
34 Correct 33 ms 154344 KB Output is correct
35 Correct 34 ms 154192 KB Output is correct
36 Correct 34 ms 154200 KB Output is correct
37 Correct 33 ms 154156 KB Output is correct
38 Correct 33 ms 156400 KB Output is correct
39 Correct 34 ms 156448 KB Output is correct
40 Correct 35 ms 156504 KB Output is correct
41 Correct 38 ms 159192 KB Output is correct
42 Correct 38 ms 158936 KB Output is correct
43 Correct 36 ms 159036 KB Output is correct
44 Correct 37 ms 158936 KB Output is correct
45 Correct 38 ms 158936 KB Output is correct
46 Incorrect 37 ms 159060 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 154192 KB Output is correct
2 Correct 33 ms 154196 KB Output is correct
3 Correct 33 ms 154204 KB Output is correct
4 Correct 33 ms 154200 KB Output is correct
5 Correct 34 ms 154204 KB Output is correct
6 Correct 33 ms 154204 KB Output is correct
7 Correct 33 ms 154204 KB Output is correct
8 Correct 33 ms 154376 KB Output is correct
9 Correct 33 ms 154232 KB Output is correct
10 Correct 33 ms 154204 KB Output is correct
11 Correct 34 ms 156252 KB Output is correct
12 Correct 33 ms 154204 KB Output is correct
13 Correct 656 ms 258240 KB Output is correct
14 Correct 751 ms 271512 KB Output is correct
15 Correct 921 ms 288396 KB Output is correct
16 Correct 1094 ms 307372 KB Output is correct
17 Correct 1388 ms 325908 KB Output is correct
18 Correct 1316 ms 325220 KB Output is correct
19 Correct 1332 ms 324576 KB Output is correct
20 Correct 33 ms 154200 KB Output is correct
21 Correct 33 ms 154192 KB Output is correct
22 Correct 35 ms 154352 KB Output is correct
23 Correct 33 ms 154292 KB Output is correct
24 Correct 34 ms 154204 KB Output is correct
25 Correct 34 ms 156408 KB Output is correct
26 Correct 36 ms 156252 KB Output is correct
27 Correct 34 ms 154348 KB Output is correct
28 Correct 33 ms 156244 KB Output is correct
29 Correct 37 ms 156180 KB Output is correct
30 Correct 34 ms 156208 KB Output is correct
31 Correct 33 ms 154376 KB Output is correct
32 Correct 35 ms 156244 KB Output is correct
33 Correct 33 ms 156340 KB Output is correct
34 Correct 33 ms 154200 KB Output is correct
35 Correct 33 ms 154204 KB Output is correct
36 Correct 33 ms 156252 KB Output is correct
37 Correct 33 ms 154356 KB Output is correct
38 Correct 34 ms 156456 KB Output is correct
39 Correct 34 ms 156404 KB Output is correct
40 Correct 34 ms 156244 KB Output is correct
41 Correct 34 ms 156248 KB Output is correct
42 Correct 34 ms 156252 KB Output is correct
43 Correct 34 ms 156252 KB Output is correct
44 Correct 34 ms 156252 KB Output is correct
45 Correct 33 ms 156240 KB Output is correct
46 Correct 34 ms 156600 KB Output is correct
47 Correct 34 ms 156244 KB Output is correct
48 Correct 33 ms 156452 KB Output is correct
49 Correct 35 ms 156240 KB Output is correct
50 Correct 34 ms 156240 KB Output is correct
51 Correct 33 ms 154344 KB Output is correct
52 Correct 34 ms 154192 KB Output is correct
53 Correct 34 ms 154200 KB Output is correct
54 Correct 33 ms 154156 KB Output is correct
55 Correct 33 ms 156400 KB Output is correct
56 Correct 34 ms 156448 KB Output is correct
57 Correct 35 ms 156504 KB Output is correct
58 Correct 38 ms 159192 KB Output is correct
59 Correct 38 ms 158936 KB Output is correct
60 Correct 36 ms 159036 KB Output is correct
61 Correct 37 ms 158936 KB Output is correct
62 Correct 38 ms 158936 KB Output is correct
63 Incorrect 37 ms 159060 KB Output isn't correct
64 Halted 0 ms 0 KB -