Submission #904832

# Submission time Handle Problem Language Result Execution time Memory
904832 2024-01-12T09:33:13 Z Tuanlinh123 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
1473 ms 683348 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][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])
            {
                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 49 ms 153692 KB Output is correct
2 Correct 49 ms 153668 KB Output is correct
3 Correct 46 ms 153692 KB Output is correct
4 Correct 47 ms 153692 KB Output is correct
5 Correct 48 ms 153976 KB Output is correct
6 Correct 48 ms 153804 KB Output is correct
7 Correct 46 ms 153676 KB Output is correct
8 Correct 46 ms 153688 KB Output is correct
9 Correct 47 ms 153680 KB Output is correct
10 Correct 47 ms 153680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 153692 KB Output is correct
2 Correct 47 ms 153692 KB Output is correct
3 Correct 135 ms 233296 KB Output is correct
4 Correct 160 ms 241748 KB Output is correct
5 Correct 196 ms 251368 KB Output is correct
6 Correct 220 ms 256344 KB Output is correct
7 Correct 266 ms 261204 KB Output is correct
8 Correct 269 ms 261192 KB Output is correct
9 Correct 270 ms 261204 KB Output is correct
10 Correct 47 ms 153604 KB Output is correct
11 Correct 49 ms 153936 KB Output is correct
12 Correct 50 ms 153684 KB Output is correct
13 Correct 46 ms 153680 KB Output is correct
14 Correct 47 ms 153692 KB Output is correct
15 Correct 48 ms 153688 KB Output is correct
16 Correct 48 ms 158032 KB Output is correct
17 Correct 49 ms 153692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 153692 KB Output is correct
2 Correct 49 ms 153668 KB Output is correct
3 Correct 46 ms 153692 KB Output is correct
4 Correct 47 ms 153692 KB Output is correct
5 Correct 48 ms 153976 KB Output is correct
6 Correct 48 ms 153804 KB Output is correct
7 Correct 46 ms 153676 KB Output is correct
8 Correct 46 ms 153688 KB Output is correct
9 Correct 47 ms 153680 KB Output is correct
10 Correct 47 ms 153680 KB Output is correct
11 Correct 47 ms 153680 KB Output is correct
12 Correct 49 ms 153904 KB Output is correct
13 Correct 49 ms 155984 KB Output is correct
14 Correct 48 ms 153796 KB Output is correct
15 Correct 51 ms 155820 KB Output is correct
16 Correct 47 ms 153680 KB Output is correct
17 Correct 47 ms 153680 KB Output is correct
18 Correct 47 ms 153784 KB Output is correct
19 Correct 47 ms 153692 KB Output is correct
20 Correct 49 ms 153684 KB Output is correct
21 Correct 48 ms 157836 KB Output is correct
22 Correct 53 ms 158040 KB Output is correct
23 Correct 48 ms 158036 KB Output is correct
24 Correct 48 ms 158032 KB Output is correct
25 Correct 49 ms 158128 KB Output is correct
26 Correct 47 ms 158036 KB Output is correct
27 Correct 52 ms 158088 KB Output is correct
28 Correct 49 ms 158032 KB Output is correct
29 Correct 48 ms 158044 KB Output is correct
30 Correct 48 ms 158288 KB Output is correct
31 Correct 51 ms 158296 KB Output is correct
32 Correct 49 ms 158100 KB Output is correct
33 Correct 49 ms 157996 KB Output is correct
34 Correct 47 ms 153540 KB Output is correct
35 Correct 46 ms 153684 KB Output is correct
36 Correct 47 ms 153692 KB Output is correct
37 Correct 48 ms 153940 KB Output is correct
38 Correct 51 ms 153684 KB Output is correct
39 Correct 48 ms 158032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 153692 KB Output is correct
2 Correct 49 ms 153668 KB Output is correct
3 Correct 46 ms 153692 KB Output is correct
4 Correct 47 ms 153692 KB Output is correct
5 Correct 48 ms 153976 KB Output is correct
6 Correct 48 ms 153804 KB Output is correct
7 Correct 46 ms 153676 KB Output is correct
8 Correct 46 ms 153688 KB Output is correct
9 Correct 47 ms 153680 KB Output is correct
10 Correct 47 ms 153680 KB Output is correct
11 Correct 47 ms 153680 KB Output is correct
12 Correct 49 ms 153904 KB Output is correct
13 Correct 49 ms 155984 KB Output is correct
14 Correct 48 ms 153796 KB Output is correct
15 Correct 51 ms 155820 KB Output is correct
16 Correct 47 ms 153680 KB Output is correct
17 Correct 47 ms 153680 KB Output is correct
18 Correct 47 ms 153784 KB Output is correct
19 Correct 47 ms 153692 KB Output is correct
20 Correct 49 ms 153684 KB Output is correct
21 Correct 48 ms 157836 KB Output is correct
22 Correct 53 ms 158040 KB Output is correct
23 Correct 48 ms 158036 KB Output is correct
24 Correct 48 ms 158032 KB Output is correct
25 Correct 49 ms 158128 KB Output is correct
26 Correct 47 ms 158036 KB Output is correct
27 Correct 52 ms 158088 KB Output is correct
28 Correct 49 ms 158032 KB Output is correct
29 Correct 48 ms 158044 KB Output is correct
30 Correct 48 ms 158288 KB Output is correct
31 Correct 51 ms 158296 KB Output is correct
32 Correct 49 ms 158100 KB Output is correct
33 Correct 49 ms 157996 KB Output is correct
34 Correct 47 ms 153540 KB Output is correct
35 Correct 46 ms 153684 KB Output is correct
36 Correct 47 ms 153692 KB Output is correct
37 Correct 48 ms 153940 KB Output is correct
38 Correct 51 ms 153684 KB Output is correct
39 Correct 48 ms 158032 KB Output is correct
40 Correct 50 ms 160644 KB Output is correct
41 Correct 51 ms 161060 KB Output is correct
42 Correct 53 ms 163412 KB Output is correct
43 Correct 55 ms 163408 KB Output is correct
44 Correct 51 ms 163676 KB Output is correct
45 Correct 51 ms 163708 KB Output is correct
46 Correct 50 ms 163716 KB Output is correct
47 Correct 50 ms 161620 KB Output is correct
48 Correct 51 ms 162396 KB Output is correct
49 Correct 52 ms 162928 KB Output is correct
50 Correct 53 ms 162892 KB Output is correct
51 Correct 54 ms 162388 KB Output is correct
52 Correct 51 ms 162384 KB Output is correct
53 Correct 50 ms 163668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 153692 KB Output is correct
2 Correct 49 ms 153668 KB Output is correct
3 Correct 46 ms 153692 KB Output is correct
4 Correct 47 ms 153692 KB Output is correct
5 Correct 48 ms 153976 KB Output is correct
6 Correct 48 ms 153804 KB Output is correct
7 Correct 46 ms 153676 KB Output is correct
8 Correct 46 ms 153688 KB Output is correct
9 Correct 47 ms 153680 KB Output is correct
10 Correct 47 ms 153680 KB Output is correct
11 Correct 47 ms 153680 KB Output is correct
12 Correct 49 ms 153904 KB Output is correct
13 Correct 49 ms 155984 KB Output is correct
14 Correct 48 ms 153796 KB Output is correct
15 Correct 51 ms 155820 KB Output is correct
16 Correct 47 ms 153680 KB Output is correct
17 Correct 47 ms 153680 KB Output is correct
18 Correct 47 ms 153784 KB Output is correct
19 Correct 47 ms 153692 KB Output is correct
20 Correct 49 ms 153684 KB Output is correct
21 Correct 48 ms 157836 KB Output is correct
22 Correct 53 ms 158040 KB Output is correct
23 Correct 48 ms 158036 KB Output is correct
24 Correct 48 ms 158032 KB Output is correct
25 Correct 49 ms 158128 KB Output is correct
26 Correct 47 ms 158036 KB Output is correct
27 Correct 52 ms 158088 KB Output is correct
28 Correct 49 ms 158032 KB Output is correct
29 Correct 48 ms 158044 KB Output is correct
30 Correct 48 ms 158288 KB Output is correct
31 Correct 51 ms 158296 KB Output is correct
32 Correct 49 ms 158100 KB Output is correct
33 Correct 49 ms 157996 KB Output is correct
34 Correct 47 ms 153540 KB Output is correct
35 Correct 46 ms 153684 KB Output is correct
36 Correct 47 ms 153692 KB Output is correct
37 Correct 48 ms 153940 KB Output is correct
38 Correct 51 ms 153684 KB Output is correct
39 Correct 48 ms 158032 KB Output is correct
40 Correct 50 ms 160644 KB Output is correct
41 Correct 51 ms 161060 KB Output is correct
42 Correct 53 ms 163412 KB Output is correct
43 Correct 55 ms 163408 KB Output is correct
44 Correct 51 ms 163676 KB Output is correct
45 Correct 51 ms 163708 KB Output is correct
46 Correct 50 ms 163716 KB Output is correct
47 Correct 50 ms 161620 KB Output is correct
48 Correct 51 ms 162396 KB Output is correct
49 Correct 52 ms 162928 KB Output is correct
50 Correct 53 ms 162892 KB Output is correct
51 Correct 54 ms 162388 KB Output is correct
52 Correct 51 ms 162384 KB Output is correct
53 Correct 50 ms 163668 KB Output is correct
54 Correct 71 ms 185940 KB Output is correct
55 Correct 75 ms 194308 KB Output is correct
56 Correct 154 ms 260904 KB Output is correct
57 Correct 134 ms 261428 KB Output is correct
58 Correct 125 ms 261712 KB Output is correct
59 Correct 107 ms 261716 KB Output is correct
60 Correct 104 ms 261984 KB Output is correct
61 Correct 103 ms 221520 KB Output is correct
62 Correct 76 ms 195048 KB Output is correct
63 Correct 110 ms 244424 KB Output is correct
64 Correct 111 ms 245136 KB Output is correct
65 Correct 141 ms 226436 KB Output is correct
66 Correct 147 ms 226664 KB Output is correct
67 Correct 108 ms 261840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 153692 KB Output is correct
2 Correct 49 ms 153668 KB Output is correct
3 Correct 46 ms 153692 KB Output is correct
4 Correct 47 ms 153692 KB Output is correct
5 Correct 48 ms 153976 KB Output is correct
6 Correct 48 ms 153804 KB Output is correct
7 Correct 46 ms 153676 KB Output is correct
8 Correct 46 ms 153688 KB Output is correct
9 Correct 47 ms 153680 KB Output is correct
10 Correct 47 ms 153680 KB Output is correct
11 Correct 46 ms 153692 KB Output is correct
12 Correct 47 ms 153692 KB Output is correct
13 Correct 135 ms 233296 KB Output is correct
14 Correct 160 ms 241748 KB Output is correct
15 Correct 196 ms 251368 KB Output is correct
16 Correct 220 ms 256344 KB Output is correct
17 Correct 266 ms 261204 KB Output is correct
18 Correct 269 ms 261192 KB Output is correct
19 Correct 270 ms 261204 KB Output is correct
20 Correct 47 ms 153604 KB Output is correct
21 Correct 49 ms 153936 KB Output is correct
22 Correct 50 ms 153684 KB Output is correct
23 Correct 46 ms 153680 KB Output is correct
24 Correct 47 ms 153692 KB Output is correct
25 Correct 48 ms 153688 KB Output is correct
26 Correct 48 ms 158032 KB Output is correct
27 Correct 49 ms 153692 KB Output is correct
28 Correct 47 ms 153680 KB Output is correct
29 Correct 49 ms 153904 KB Output is correct
30 Correct 49 ms 155984 KB Output is correct
31 Correct 48 ms 153796 KB Output is correct
32 Correct 51 ms 155820 KB Output is correct
33 Correct 47 ms 153680 KB Output is correct
34 Correct 47 ms 153680 KB Output is correct
35 Correct 47 ms 153784 KB Output is correct
36 Correct 47 ms 153692 KB Output is correct
37 Correct 49 ms 153684 KB Output is correct
38 Correct 48 ms 157836 KB Output is correct
39 Correct 53 ms 158040 KB Output is correct
40 Correct 48 ms 158036 KB Output is correct
41 Correct 48 ms 158032 KB Output is correct
42 Correct 49 ms 158128 KB Output is correct
43 Correct 47 ms 158036 KB Output is correct
44 Correct 52 ms 158088 KB Output is correct
45 Correct 49 ms 158032 KB Output is correct
46 Correct 48 ms 158044 KB Output is correct
47 Correct 48 ms 158288 KB Output is correct
48 Correct 51 ms 158296 KB Output is correct
49 Correct 49 ms 158100 KB Output is correct
50 Correct 49 ms 157996 KB Output is correct
51 Correct 47 ms 153540 KB Output is correct
52 Correct 46 ms 153684 KB Output is correct
53 Correct 47 ms 153692 KB Output is correct
54 Correct 48 ms 153940 KB Output is correct
55 Correct 51 ms 153684 KB Output is correct
56 Correct 48 ms 158032 KB Output is correct
57 Correct 50 ms 160644 KB Output is correct
58 Correct 51 ms 161060 KB Output is correct
59 Correct 53 ms 163412 KB Output is correct
60 Correct 55 ms 163408 KB Output is correct
61 Correct 51 ms 163676 KB Output is correct
62 Correct 51 ms 163708 KB Output is correct
63 Correct 50 ms 163716 KB Output is correct
64 Correct 50 ms 161620 KB Output is correct
65 Correct 51 ms 162396 KB Output is correct
66 Correct 52 ms 162928 KB Output is correct
67 Correct 53 ms 162892 KB Output is correct
68 Correct 54 ms 162388 KB Output is correct
69 Correct 51 ms 162384 KB Output is correct
70 Correct 50 ms 163668 KB Output is correct
71 Correct 71 ms 185940 KB Output is correct
72 Correct 75 ms 194308 KB Output is correct
73 Correct 154 ms 260904 KB Output is correct
74 Correct 134 ms 261428 KB Output is correct
75 Correct 125 ms 261712 KB Output is correct
76 Correct 107 ms 261716 KB Output is correct
77 Correct 104 ms 261984 KB Output is correct
78 Correct 103 ms 221520 KB Output is correct
79 Correct 76 ms 195048 KB Output is correct
80 Correct 110 ms 244424 KB Output is correct
81 Correct 111 ms 245136 KB Output is correct
82 Correct 141 ms 226436 KB Output is correct
83 Correct 147 ms 226664 KB Output is correct
84 Correct 108 ms 261840 KB Output is correct
85 Correct 342 ms 388916 KB Output is correct
86 Correct 1473 ms 680560 KB Output is correct
87 Correct 599 ms 681556 KB Output is correct
88 Correct 453 ms 682656 KB Output is correct
89 Correct 405 ms 683092 KB Output is correct
90 Correct 391 ms 683256 KB Output is correct
91 Correct 544 ms 280992 KB Output is correct
92 Correct 275 ms 265652 KB Output is correct
93 Correct 411 ms 549292 KB Output is correct
94 Correct 526 ms 576340 KB Output is correct
95 Correct 882 ms 458788 KB Output is correct
96 Correct 847 ms 458556 KB Output is correct
97 Correct 402 ms 683348 KB Output is correct