Submission #904830

# Submission time Handle Problem Language Result Execution time Memory
904830 2024-01-12T09:25:35 Z Tuanlinh123 Copy and Paste 3 (JOI22_copypaste3) C++17
30 / 100
183 ms 262008 KB
#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

const ll maxn=2505;
vector <ll> pos[maxn*maxn];
ll crr, go[maxn*maxn][26];
long long check[maxn*maxn];
ll pi[maxn][maxn], idx[maxn][maxn], cnt[maxn][maxn], R[maxn][maxn];

inline ll calc(ll l, ll r, ll q)
{
    ll id=idx[l][r], len=r-l+1;
    while (1)
    {
        ll p=upper_bound(pos[id].begin(), pos[id].end(), R[l][r])-pos[id].begin();
        if (p>=pos[id].size() || pos[id][p]+len-1>q) break;
        cnt[l][r]++, R[l][r]=pos[id][p]+len-1;
    }
    return cnt[l][r];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n; cin >> n;
    string s; cin >> s; s='$'+s;
    long long A, B, C; cin >> A >> B >> C;
    for (ll i=1; i<=n; i++)
    {
        for (ll j=i+1; j<=n; j++)
        {
            ll k=pi[i][j-1];
            while (k && s[i+k]!=s[j])
                k=pi[i][k-1];   
            pi[i][j]=k+(s[i+k]==s[j]);
        }
        for (ll j=i, p=0; j<=n; j++)
        {
            ll c=s[j]-'a';
            if (!go[p][c]) go[p][c]=++crr;
            p=go[p][c], idx[i][j]=p;
            pos[idx[i][j]].pb(i);
            R[i][j]=j, cnt[i][j]=1;
        }
    }
    for (ll len=1; len<=n; len++)
    {
        for (ll i=1; i+len<=n+1; i++)
        {
            ll j=i+len-1, crr=pi[i][j];
            if (check[idx[i][j]])
                continue;
            check[idx[i][j]]=A*len;
            if (i<j) check[idx[i][j]]=min({check[idx[i][j]], check[idx[i+1][j]]+A, check[idx[i][j-1]]+A});
            for (; crr; crr=pi[i][i+crr-1])
                if (crr*2<=len)
                {
                    ll c=calc(i, i+crr-1, j);
                    long long val=check[idx[i][i+crr-1]];
                    check[idx[i][j]]=min(check[idx[i][j]], val+B+C*c+A*(len-crr*c));
                }
        }
    }
    cout << check[idx[1][n]];
}

Compilation message

copypaste3.cpp: In function 'int calc(int, int, int)':
copypaste3.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         if (p>=pos[id].size() || pos[id][p]+len-1>q) break;
      |             ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 78 ms 153792 KB Output is correct
2 Correct 47 ms 153708 KB Output is correct
3 Correct 47 ms 153680 KB Output is correct
4 Correct 47 ms 153680 KB Output is correct
5 Correct 47 ms 153604 KB Output is correct
6 Correct 47 ms 153692 KB Output is correct
7 Correct 48 ms 153688 KB Output is correct
8 Correct 49 ms 153860 KB Output is correct
9 Correct 47 ms 153688 KB Output is correct
10 Correct 48 ms 153800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 153692 KB Output is correct
2 Correct 48 ms 153692 KB Output is correct
3 Correct 130 ms 233268 KB Output is correct
4 Correct 138 ms 241744 KB Output is correct
5 Correct 150 ms 251144 KB Output is correct
6 Correct 169 ms 256232 KB Output is correct
7 Correct 182 ms 260980 KB Output is correct
8 Correct 182 ms 261196 KB Output is correct
9 Correct 183 ms 261204 KB Output is correct
10 Correct 48 ms 153788 KB Output is correct
11 Correct 47 ms 153688 KB Output is correct
12 Correct 47 ms 153684 KB Output is correct
13 Correct 47 ms 153692 KB Output is correct
14 Correct 48 ms 153608 KB Output is correct
15 Correct 47 ms 153688 KB Output is correct
16 Correct 49 ms 158044 KB Output is correct
17 Correct 48 ms 153804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 153792 KB Output is correct
2 Correct 47 ms 153708 KB Output is correct
3 Correct 47 ms 153680 KB Output is correct
4 Correct 47 ms 153680 KB Output is correct
5 Correct 47 ms 153604 KB Output is correct
6 Correct 47 ms 153692 KB Output is correct
7 Correct 48 ms 153688 KB Output is correct
8 Correct 49 ms 153860 KB Output is correct
9 Correct 47 ms 153688 KB Output is correct
10 Correct 48 ms 153800 KB Output is correct
11 Correct 48 ms 153692 KB Output is correct
12 Correct 48 ms 153692 KB Output is correct
13 Correct 50 ms 155992 KB Output is correct
14 Correct 51 ms 153840 KB Output is correct
15 Correct 47 ms 155992 KB Output is correct
16 Correct 50 ms 153696 KB Output is correct
17 Correct 47 ms 153828 KB Output is correct
18 Correct 47 ms 153692 KB Output is correct
19 Correct 47 ms 154120 KB Output is correct
20 Correct 47 ms 153824 KB Output is correct
21 Correct 48 ms 158296 KB Output is correct
22 Correct 49 ms 158044 KB Output is correct
23 Correct 48 ms 158040 KB Output is correct
24 Correct 50 ms 158132 KB Output is correct
25 Correct 49 ms 158036 KB Output is correct
26 Correct 49 ms 158092 KB Output is correct
27 Correct 48 ms 158036 KB Output is correct
28 Correct 49 ms 158092 KB Output is correct
29 Correct 49 ms 158032 KB Output is correct
30 Correct 48 ms 158032 KB Output is correct
31 Correct 48 ms 158076 KB Output is correct
32 Correct 48 ms 158040 KB Output is correct
33 Correct 49 ms 158060 KB Output is correct
34 Correct 49 ms 153644 KB Output is correct
35 Correct 47 ms 153680 KB Output is correct
36 Correct 47 ms 153692 KB Output is correct
37 Correct 47 ms 153692 KB Output is correct
38 Correct 48 ms 153884 KB Output is correct
39 Correct 49 ms 158032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 153792 KB Output is correct
2 Correct 47 ms 153708 KB Output is correct
3 Correct 47 ms 153680 KB Output is correct
4 Correct 47 ms 153680 KB Output is correct
5 Correct 47 ms 153604 KB Output is correct
6 Correct 47 ms 153692 KB Output is correct
7 Correct 48 ms 153688 KB Output is correct
8 Correct 49 ms 153860 KB Output is correct
9 Correct 47 ms 153688 KB Output is correct
10 Correct 48 ms 153800 KB Output is correct
11 Correct 48 ms 153692 KB Output is correct
12 Correct 48 ms 153692 KB Output is correct
13 Correct 50 ms 155992 KB Output is correct
14 Correct 51 ms 153840 KB Output is correct
15 Correct 47 ms 155992 KB Output is correct
16 Correct 50 ms 153696 KB Output is correct
17 Correct 47 ms 153828 KB Output is correct
18 Correct 47 ms 153692 KB Output is correct
19 Correct 47 ms 154120 KB Output is correct
20 Correct 47 ms 153824 KB Output is correct
21 Correct 48 ms 158296 KB Output is correct
22 Correct 49 ms 158044 KB Output is correct
23 Correct 48 ms 158040 KB Output is correct
24 Correct 50 ms 158132 KB Output is correct
25 Correct 49 ms 158036 KB Output is correct
26 Correct 49 ms 158092 KB Output is correct
27 Correct 48 ms 158036 KB Output is correct
28 Correct 49 ms 158092 KB Output is correct
29 Correct 49 ms 158032 KB Output is correct
30 Correct 48 ms 158032 KB Output is correct
31 Correct 48 ms 158076 KB Output is correct
32 Correct 48 ms 158040 KB Output is correct
33 Correct 49 ms 158060 KB Output is correct
34 Correct 49 ms 153644 KB Output is correct
35 Correct 47 ms 153680 KB Output is correct
36 Correct 47 ms 153692 KB Output is correct
37 Correct 47 ms 153692 KB Output is correct
38 Correct 48 ms 153884 KB Output is correct
39 Correct 49 ms 158032 KB Output is correct
40 Correct 52 ms 160852 KB Output is correct
41 Correct 50 ms 161032 KB Output is correct
42 Correct 52 ms 163412 KB Output is correct
43 Correct 52 ms 163404 KB Output is correct
44 Correct 51 ms 163472 KB Output is correct
45 Correct 51 ms 163672 KB Output is correct
46 Correct 52 ms 163664 KB Output is correct
47 Correct 53 ms 161616 KB Output is correct
48 Correct 51 ms 162388 KB Output is correct
49 Correct 50 ms 162900 KB Output is correct
50 Correct 51 ms 163008 KB Output is correct
51 Correct 53 ms 162384 KB Output is correct
52 Correct 52 ms 162396 KB Output is correct
53 Correct 52 ms 163488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 153792 KB Output is correct
2 Correct 47 ms 153708 KB Output is correct
3 Correct 47 ms 153680 KB Output is correct
4 Correct 47 ms 153680 KB Output is correct
5 Correct 47 ms 153604 KB Output is correct
6 Correct 47 ms 153692 KB Output is correct
7 Correct 48 ms 153688 KB Output is correct
8 Correct 49 ms 153860 KB Output is correct
9 Correct 47 ms 153688 KB Output is correct
10 Correct 48 ms 153800 KB Output is correct
11 Correct 48 ms 153692 KB Output is correct
12 Correct 48 ms 153692 KB Output is correct
13 Correct 50 ms 155992 KB Output is correct
14 Correct 51 ms 153840 KB Output is correct
15 Correct 47 ms 155992 KB Output is correct
16 Correct 50 ms 153696 KB Output is correct
17 Correct 47 ms 153828 KB Output is correct
18 Correct 47 ms 153692 KB Output is correct
19 Correct 47 ms 154120 KB Output is correct
20 Correct 47 ms 153824 KB Output is correct
21 Correct 48 ms 158296 KB Output is correct
22 Correct 49 ms 158044 KB Output is correct
23 Correct 48 ms 158040 KB Output is correct
24 Correct 50 ms 158132 KB Output is correct
25 Correct 49 ms 158036 KB Output is correct
26 Correct 49 ms 158092 KB Output is correct
27 Correct 48 ms 158036 KB Output is correct
28 Correct 49 ms 158092 KB Output is correct
29 Correct 49 ms 158032 KB Output is correct
30 Correct 48 ms 158032 KB Output is correct
31 Correct 48 ms 158076 KB Output is correct
32 Correct 48 ms 158040 KB Output is correct
33 Correct 49 ms 158060 KB Output is correct
34 Correct 49 ms 153644 KB Output is correct
35 Correct 47 ms 153680 KB Output is correct
36 Correct 47 ms 153692 KB Output is correct
37 Correct 47 ms 153692 KB Output is correct
38 Correct 48 ms 153884 KB Output is correct
39 Correct 49 ms 158032 KB Output is correct
40 Correct 52 ms 160852 KB Output is correct
41 Correct 50 ms 161032 KB Output is correct
42 Correct 52 ms 163412 KB Output is correct
43 Correct 52 ms 163404 KB Output is correct
44 Correct 51 ms 163472 KB Output is correct
45 Correct 51 ms 163672 KB Output is correct
46 Correct 52 ms 163664 KB Output is correct
47 Correct 53 ms 161616 KB Output is correct
48 Correct 51 ms 162388 KB Output is correct
49 Correct 50 ms 162900 KB Output is correct
50 Correct 51 ms 163008 KB Output is correct
51 Correct 53 ms 162384 KB Output is correct
52 Correct 52 ms 162396 KB Output is correct
53 Correct 52 ms 163488 KB Output is correct
54 Correct 69 ms 185944 KB Output is correct
55 Correct 73 ms 194388 KB Output is correct
56 Correct 148 ms 260948 KB Output is correct
57 Correct 128 ms 261480 KB Output is correct
58 Correct 111 ms 261792 KB Output is correct
59 Correct 114 ms 261744 KB Output is correct
60 Correct 111 ms 262008 KB Output is correct
61 Correct 95 ms 221520 KB Output is correct
62 Correct 80 ms 195060 KB Output is correct
63 Correct 117 ms 244380 KB Output is correct
64 Correct 114 ms 245076 KB Output is correct
65 Incorrect 115 ms 226384 KB Output isn't correct
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 153792 KB Output is correct
2 Correct 47 ms 153708 KB Output is correct
3 Correct 47 ms 153680 KB Output is correct
4 Correct 47 ms 153680 KB Output is correct
5 Correct 47 ms 153604 KB Output is correct
6 Correct 47 ms 153692 KB Output is correct
7 Correct 48 ms 153688 KB Output is correct
8 Correct 49 ms 153860 KB Output is correct
9 Correct 47 ms 153688 KB Output is correct
10 Correct 48 ms 153800 KB Output is correct
11 Correct 48 ms 153692 KB Output is correct
12 Correct 48 ms 153692 KB Output is correct
13 Correct 130 ms 233268 KB Output is correct
14 Correct 138 ms 241744 KB Output is correct
15 Correct 150 ms 251144 KB Output is correct
16 Correct 169 ms 256232 KB Output is correct
17 Correct 182 ms 260980 KB Output is correct
18 Correct 182 ms 261196 KB Output is correct
19 Correct 183 ms 261204 KB Output is correct
20 Correct 48 ms 153788 KB Output is correct
21 Correct 47 ms 153688 KB Output is correct
22 Correct 47 ms 153684 KB Output is correct
23 Correct 47 ms 153692 KB Output is correct
24 Correct 48 ms 153608 KB Output is correct
25 Correct 47 ms 153688 KB Output is correct
26 Correct 49 ms 158044 KB Output is correct
27 Correct 48 ms 153804 KB Output is correct
28 Correct 48 ms 153692 KB Output is correct
29 Correct 48 ms 153692 KB Output is correct
30 Correct 50 ms 155992 KB Output is correct
31 Correct 51 ms 153840 KB Output is correct
32 Correct 47 ms 155992 KB Output is correct
33 Correct 50 ms 153696 KB Output is correct
34 Correct 47 ms 153828 KB Output is correct
35 Correct 47 ms 153692 KB Output is correct
36 Correct 47 ms 154120 KB Output is correct
37 Correct 47 ms 153824 KB Output is correct
38 Correct 48 ms 158296 KB Output is correct
39 Correct 49 ms 158044 KB Output is correct
40 Correct 48 ms 158040 KB Output is correct
41 Correct 50 ms 158132 KB Output is correct
42 Correct 49 ms 158036 KB Output is correct
43 Correct 49 ms 158092 KB Output is correct
44 Correct 48 ms 158036 KB Output is correct
45 Correct 49 ms 158092 KB Output is correct
46 Correct 49 ms 158032 KB Output is correct
47 Correct 48 ms 158032 KB Output is correct
48 Correct 48 ms 158076 KB Output is correct
49 Correct 48 ms 158040 KB Output is correct
50 Correct 49 ms 158060 KB Output is correct
51 Correct 49 ms 153644 KB Output is correct
52 Correct 47 ms 153680 KB Output is correct
53 Correct 47 ms 153692 KB Output is correct
54 Correct 47 ms 153692 KB Output is correct
55 Correct 48 ms 153884 KB Output is correct
56 Correct 49 ms 158032 KB Output is correct
57 Correct 52 ms 160852 KB Output is correct
58 Correct 50 ms 161032 KB Output is correct
59 Correct 52 ms 163412 KB Output is correct
60 Correct 52 ms 163404 KB Output is correct
61 Correct 51 ms 163472 KB Output is correct
62 Correct 51 ms 163672 KB Output is correct
63 Correct 52 ms 163664 KB Output is correct
64 Correct 53 ms 161616 KB Output is correct
65 Correct 51 ms 162388 KB Output is correct
66 Correct 50 ms 162900 KB Output is correct
67 Correct 51 ms 163008 KB Output is correct
68 Correct 53 ms 162384 KB Output is correct
69 Correct 52 ms 162396 KB Output is correct
70 Correct 52 ms 163488 KB Output is correct
71 Correct 69 ms 185944 KB Output is correct
72 Correct 73 ms 194388 KB Output is correct
73 Correct 148 ms 260948 KB Output is correct
74 Correct 128 ms 261480 KB Output is correct
75 Correct 111 ms 261792 KB Output is correct
76 Correct 114 ms 261744 KB Output is correct
77 Correct 111 ms 262008 KB Output is correct
78 Correct 95 ms 221520 KB Output is correct
79 Correct 80 ms 195060 KB Output is correct
80 Correct 117 ms 244380 KB Output is correct
81 Correct 114 ms 245076 KB Output is correct
82 Incorrect 115 ms 226384 KB Output isn't correct
83 Halted 0 ms 0 KB -