Submission #883802

# Submission time Handle Problem Language Result Execution time Memory
883802 2023-12-06T05:20:00 Z gaga999 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
254 ms 72788 KB
#include <cstdio>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <cstring>
#include <string.h>
#include <string>
#include <sstream>
#include <assert.h>
#include <climits>
#include <sstream>
#include <numeric>
#include <time.h>
#include <limits.h>
#include <list>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <complex>
#include <chrono>
#include <fstream>
#include <functional>
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx,avx2,bmi,bmi2,lzcnt,popcnt")
#define lowbit(x) ((x) & -(x))
#define ml(a, b) ((1ll * (a) * (b)) % M)
#define tml(a, b) (a) = ((1ll * (a) * (b)) % M)
#define ad(a, b) ((0ll + (a) + (b)) % M)
#define tad(a, b) (a) = ((0ll + (a) + (b)) % M)
#define mi(a, b) ((0ll + M + (a) - (b)) % M)
#define tmi(a, b) (a) = ((0ll + M + (a) - (b)) % M)
#define tmin(a, b) (a) = min((a), (b))
#define tmax(a, b) (a) = max((a), (b))
#define iter(a) (a).begin(), (a).end()
#define riter(a) (a).rbegin(), (a).rend()
#define init(a, b) memset((a), (b), sizeof(a))
#define cpy(a, b) memcpy((a), (b), sizeof(a))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define pb emplace_back
#define mpr make_pair
#define ls(i) ((i) << 1)
#define rs(i) ((i) << 1 | 1)
#define INF 0x3f3f3f3f
#define NIF 0xc0c0c0c0
#define eps 1e-9
#define F first
#define S second
#define AC cin.tie(0)->sync_with_stdio(0)
using namespace std;
typedef long long llt;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<llt, llt> pll;
typedef complex<double> cd;
// const int M = 998244353;

// random_device rm;
// mt19937 rg(rm());
// default_random_engine rg(rm());
// uniform_int_distribution<int> rd(INT_MIN, INT_MAX);
// uniform_real_distribution<double> rd(0, M_PI);

void db() { cerr << "\n"; }
template <class T, class... U>
void db(T a, U... b) { cerr << a << " ", db(b...); }

void rd() {}
template <typename T, typename... U>
void rd(T &x, U &...y)
{
    x = 0;
    bool f = 0;
    char c = getchar();
    while (!isdigit(c))
        f ^= !(c ^ 45), c = getchar();
    while (isdigit(c))
        x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    f && (x = -x), rd(y...);
}

template <typename T>
void prt(T x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        prt(x / 10);
    putchar((x % 10) ^ 48);
}

const int N = 2505;
llt dp[N][N];
int nxt[N][N], z[N];
char s[N];

signed main()
{
    int n;
    llt a, b, c;
    scanf("%d%s%lld%lld%lld", &n, s + 1, &a, &b, &c);
    for (int p = 1; p <= n; p++)
    {
        int l = p, r = p, cr = 1;
        for (int i = p + 1; i <= n; i++)
        {
            z[i] = max(0, min(r - i, z[i - l + p]));
            while (i + z[i] <= n && s[i + z[i]] == s[p + z[i]])
                z[i]++;
            if (i + z[i] > r)
                l = i, r = i + z[i];
            for (; cr <= min(z[i], i - p); cr++)
                nxt[p][cr] = i;
        }
        for (int i = 1; i + p - 1 <= n; i++)
            dp[p][i] = a * i;
    }
    for (int k = 1; k <= n; k++)
    {
        for (int i = 1; i + k - 1 <= n; i++)
        {
            tmin(dp[i][k], min(dp[i][k - 1], dp[i + 1][k - 1]) + a);
            llt cr = dp[i][k] + b;
            int ct = 1;
            for (int j = nxt[i][k]; j; j = nxt[j][k])
                ct++, tmin(dp[i][j - i + k], cr + c * ct + a * (j - i - k * (ct - 1)));
        }
    }
    prt(dp[1][n]), putchar('\n');
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:112:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |     scanf("%d%s%lld%lld%lld", &n, s + 1, &a, &b, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 110 ms 58004 KB Output is correct
4 Correct 138 ms 62292 KB Output is correct
5 Correct 172 ms 68276 KB Output is correct
6 Correct 201 ms 70268 KB Output is correct
7 Correct 254 ms 72740 KB Output is correct
8 Correct 249 ms 72788 KB Output is correct
9 Correct 253 ms 72744 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2392 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6592 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2392 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6592 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6488 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 1 ms 8540 KB Output is correct
44 Correct 1 ms 8540 KB Output is correct
45 Correct 1 ms 8540 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 1 ms 8536 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 2 ms 8540 KB Output is correct
53 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2392 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6592 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6488 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 1 ms 8540 KB Output is correct
44 Correct 1 ms 8540 KB Output is correct
45 Correct 1 ms 8540 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 1 ms 8536 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 2 ms 8540 KB Output is correct
53 Correct 1 ms 8540 KB Output is correct
54 Correct 4 ms 18780 KB Output is correct
55 Correct 25 ms 33356 KB Output is correct
56 Correct 12 ms 33368 KB Output is correct
57 Correct 11 ms 33116 KB Output is correct
58 Correct 11 ms 33348 KB Output is correct
59 Correct 8 ms 33116 KB Output is correct
60 Correct 9 ms 33112 KB Output is correct
61 Correct 10 ms 33372 KB Output is correct
62 Correct 23 ms 33376 KB Output is correct
63 Correct 9 ms 33116 KB Output is correct
64 Correct 10 ms 33368 KB Output is correct
65 Correct 16 ms 33364 KB Output is correct
66 Correct 14 ms 33112 KB Output is correct
67 Correct 8 ms 33116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 110 ms 58004 KB Output is correct
14 Correct 138 ms 62292 KB Output is correct
15 Correct 172 ms 68276 KB Output is correct
16 Correct 201 ms 70268 KB Output is correct
17 Correct 254 ms 72740 KB Output is correct
18 Correct 249 ms 72788 KB Output is correct
19 Correct 253 ms 72744 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6592 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 1 ms 6488 KB Output is correct
58 Correct 2 ms 8540 KB Output is correct
59 Correct 2 ms 8540 KB Output is correct
60 Correct 1 ms 8540 KB Output is correct
61 Correct 1 ms 8540 KB Output is correct
62 Correct 1 ms 8540 KB Output is correct
63 Correct 1 ms 8540 KB Output is correct
64 Correct 1 ms 8540 KB Output is correct
65 Correct 1 ms 8536 KB Output is correct
66 Correct 1 ms 8540 KB Output is correct
67 Correct 1 ms 8540 KB Output is correct
68 Correct 2 ms 8540 KB Output is correct
69 Correct 2 ms 8540 KB Output is correct
70 Correct 1 ms 8540 KB Output is correct
71 Correct 4 ms 18780 KB Output is correct
72 Correct 25 ms 33356 KB Output is correct
73 Correct 12 ms 33368 KB Output is correct
74 Correct 11 ms 33116 KB Output is correct
75 Correct 11 ms 33348 KB Output is correct
76 Correct 8 ms 33116 KB Output is correct
77 Correct 9 ms 33112 KB Output is correct
78 Correct 10 ms 33372 KB Output is correct
79 Correct 23 ms 33376 KB Output is correct
80 Correct 9 ms 33116 KB Output is correct
81 Correct 10 ms 33368 KB Output is correct
82 Correct 16 ms 33364 KB Output is correct
83 Correct 14 ms 33112 KB Output is correct
84 Correct 8 ms 33116 KB Output is correct
85 Correct 29 ms 49752 KB Output is correct
86 Correct 88 ms 72788 KB Output is correct
87 Correct 61 ms 72540 KB Output is correct
88 Correct 46 ms 72664 KB Output is correct
89 Correct 39 ms 72540 KB Output is correct
90 Correct 38 ms 72672 KB Output is correct
91 Correct 111 ms 72540 KB Output is correct
92 Correct 177 ms 72788 KB Output is correct
93 Correct 50 ms 72536 KB Output is correct
94 Correct 59 ms 72568 KB Output is correct
95 Correct 141 ms 72528 KB Output is correct
96 Correct 138 ms 72536 KB Output is correct
97 Correct 38 ms 72536 KB Output is correct