Submission #776699

# Submission time Handle Problem Language Result Execution time Memory
776699 2023-07-08T07:28:16 Z danikoynov Copy and Paste 3 (JOI22_copypaste3) C++14
57 / 100
583 ms 73196 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const ll maxn = 1010;
const ll base = 29, inf = 1e18;

ll n;
ll a, b, c, h[maxn], pw[maxn], dp[maxn][maxn];
string s;
unordered_map < ll, vector < ll > > occ;
unordered_map < ll, ll > hs_dp;

ll get_hash(ll i, ll j)
{
    if (i > j)
        return 0;
    return h[j] - h[i - 1] * pw[j - i + 1];
}

void solve()
{
    cin >> n >> s >> a >> b >> c;
    s = "#" + s;
    pw[0] = 1;
    for (ll i = 1; i <= n; i ++)
    {
        h[i] = h[i - 1] * base + (s[i] - 'a' + 1);
        pw[i] = pw[i - 1] * base;
    }
    for (ll i = 1; i <= n; i ++)
        for (ll j = i; j <= n; j ++)
            dp[i][j] = inf;

    for (ll i = n; i > 0; i --)
    {


        for (ll p = i; p <= n; p ++)
        {
            ll cur_hs = get_hash(i, p);
            occ[cur_hs].push_back(i);
            if (occ[cur_hs].size() == 1)
            {
                hs_dp[cur_hs] = hs_dp[get_hash(i + 1, p)] + a;
            }
            else
            {
                hs_dp[cur_hs] = min(hs_dp[cur_hs], hs_dp[get_hash(i + 1, p)] + a);
            }
        }


        for (ll k = i; k <= n; k ++)
        {
            ll clip_hash, clip_len = k - i + 1;
            clip_hash = h[k] - h[i - 1] * pw[clip_len];
            ll cost = hs_dp[clip_hash] + b;

            ll pos = i;
            while(pos <= n)
            {
                ll to = pos + clip_len - 1;
                if (to > n)
                {
                    break;
                }

                if (get_hash(pos, to) == clip_hash)
                {

                    cost = cost + c;
                    pos = pos + clip_len;
                    hs_dp[get_hash(i, to)] = min(hs_dp[get_hash(i, to)], cost);
                }
                else
                {
                    pos ++;
                    cost += a;
                }
            }

        }
        for (ll k = i; k <= n; k ++)
        {
            hs_dp[get_hash(i, k)] = min(hs_dp[get_hash(i, k)], hs_dp[get_hash(i, k - 1)] + a);
        }

    }

    cout << hs_dp[h[n]] << endl;


}

int main()
{
    solve();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 9 ms 16596 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 1108 KB Output is correct
41 Correct 8 ms 1444 KB Output is correct
42 Correct 9 ms 3636 KB Output is correct
43 Correct 8 ms 3668 KB Output is correct
44 Correct 9 ms 3668 KB Output is correct
45 Correct 8 ms 3796 KB Output is correct
46 Correct 8 ms 3768 KB Output is correct
47 Correct 7 ms 1980 KB Output is correct
48 Correct 8 ms 2900 KB Output is correct
49 Correct 8 ms 3156 KB Output is correct
50 Correct 8 ms 3156 KB Output is correct
51 Correct 9 ms 2900 KB Output is correct
52 Correct 9 ms 2900 KB Output is correct
53 Correct 8 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 1108 KB Output is correct
41 Correct 8 ms 1444 KB Output is correct
42 Correct 9 ms 3636 KB Output is correct
43 Correct 8 ms 3668 KB Output is correct
44 Correct 9 ms 3668 KB Output is correct
45 Correct 8 ms 3796 KB Output is correct
46 Correct 8 ms 3768 KB Output is correct
47 Correct 7 ms 1980 KB Output is correct
48 Correct 8 ms 2900 KB Output is correct
49 Correct 8 ms 3156 KB Output is correct
50 Correct 8 ms 3156 KB Output is correct
51 Correct 9 ms 2900 KB Output is correct
52 Correct 9 ms 2900 KB Output is correct
53 Correct 8 ms 3796 KB Output is correct
54 Correct 55 ms 16212 KB Output is correct
55 Correct 218 ms 12572 KB Output is correct
56 Correct 571 ms 72348 KB Output is correct
57 Correct 567 ms 72700 KB Output is correct
58 Correct 562 ms 73000 KB Output is correct
59 Correct 577 ms 73040 KB Output is correct
60 Correct 567 ms 73096 KB Output is correct
61 Correct 365 ms 37784 KB Output is correct
62 Correct 196 ms 13452 KB Output is correct
63 Correct 520 ms 60144 KB Output is correct
64 Correct 569 ms 60644 KB Output is correct
65 Correct 396 ms 41276 KB Output is correct
66 Correct 357 ms 41152 KB Output is correct
67 Correct 583 ms 73196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Runtime error 9 ms 16596 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -