답안 #936860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936860 2024-03-02T22:07:30 Z fyan Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
350 ms 72920 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);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 153 ms 57948 KB Output is correct
4 Correct 174 ms 62044 KB Output is correct
5 Correct 211 ms 68184 KB Output is correct
6 Correct 255 ms 70332 KB Output is correct
7 Correct 301 ms 72920 KB Output is correct
8 Correct 350 ms 72588 KB Output is correct
9 Correct 316 ms 72740 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 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 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 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 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 2392 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 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 6640 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 6492 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2392 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 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 2392 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 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 6640 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 6492 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2392 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 6492 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 8724 KB Output is correct
43 Correct 2 ms 8788 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 8540 KB Output is correct
49 Correct 2 ms 8540 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 1 ms 8540 KB Output is correct
53 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 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 2392 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 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 6640 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 6492 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2392 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 6492 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 8724 KB Output is correct
43 Correct 2 ms 8788 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 8540 KB Output is correct
49 Correct 2 ms 8540 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 1 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 28 ms 33116 KB Output is correct
56 Correct 14 ms 33344 KB Output is correct
57 Correct 12 ms 33116 KB Output is correct
58 Correct 10 ms 33304 KB Output is correct
59 Correct 9 ms 33116 KB Output is correct
60 Correct 9 ms 33348 KB Output is correct
61 Correct 12 ms 33372 KB Output is correct
62 Correct 25 ms 33372 KB Output is correct
63 Correct 11 ms 33368 KB Output is correct
64 Correct 11 ms 33372 KB Output is correct
65 Correct 19 ms 33224 KB Output is correct
66 Correct 18 ms 33372 KB Output is correct
67 Correct 9 ms 33116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 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 153 ms 57948 KB Output is correct
14 Correct 174 ms 62044 KB Output is correct
15 Correct 211 ms 68184 KB Output is correct
16 Correct 255 ms 70332 KB Output is correct
17 Correct 301 ms 72920 KB Output is correct
18 Correct 350 ms 72588 KB Output is correct
19 Correct 316 ms 72740 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 0 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 1 ms 2396 KB Output is correct
28 Correct 1 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 2392 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 1 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 6640 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 6492 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2392 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 6492 KB Output is correct
58 Correct 2 ms 8540 KB Output is correct
59 Correct 2 ms 8724 KB Output is correct
60 Correct 2 ms 8788 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 8540 KB Output is correct
66 Correct 2 ms 8540 KB Output is correct
67 Correct 2 ms 8540 KB Output is correct
68 Correct 2 ms 8540 KB Output is correct
69 Correct 1 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 28 ms 33116 KB Output is correct
73 Correct 14 ms 33344 KB Output is correct
74 Correct 12 ms 33116 KB Output is correct
75 Correct 10 ms 33304 KB Output is correct
76 Correct 9 ms 33116 KB Output is correct
77 Correct 9 ms 33348 KB Output is correct
78 Correct 12 ms 33372 KB Output is correct
79 Correct 25 ms 33372 KB Output is correct
80 Correct 11 ms 33368 KB Output is correct
81 Correct 11 ms 33372 KB Output is correct
82 Correct 19 ms 33224 KB Output is correct
83 Correct 18 ms 33372 KB Output is correct
84 Correct 9 ms 33116 KB Output is correct
85 Correct 34 ms 49744 KB Output is correct
86 Correct 92 ms 72528 KB Output is correct
87 Correct 73 ms 72528 KB Output is correct
88 Correct 61 ms 72540 KB Output is correct
89 Correct 54 ms 72584 KB Output is correct
90 Correct 49 ms 72736 KB Output is correct
91 Correct 172 ms 72748 KB Output is correct
92 Correct 208 ms 72744 KB Output is correct
93 Correct 79 ms 72744 KB Output is correct
94 Correct 91 ms 72532 KB Output is correct
95 Correct 193 ms 72788 KB Output is correct
96 Correct 181 ms 72736 KB Output is correct
97 Correct 53 ms 72532 KB Output is correct