답안 #555771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555771 2022-05-01T13:52:53 Z AriaH Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
631 ms 49616 KB
/* Im the best and i work like that */

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

#define F first
#define S second
#define all(x) x.begin(),x.end()
#define Mp make_pair
#define point complex
#define endl '\n'
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file_io freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define mashtali return cout << "Hello, World!", 0;

const int N = 2510;
const int LOG = 20;
const ll mod = 1e9 + 21;
const ll base = 6379;
const ll inf = 8e18;
const double pi = acos(-1);
const ld eps = 1e-18;
const ld one = 1.;

ll pw(ll a, ll b, ll M, ll ret = 1) { if(a == 0) return 0; a %= M; while(b) { ret = (b & 1? ret * a % M : ret), a = a * a % M, b >>= 1; } return ret % M; }

mt19937 rng(time(nullptr));

int n, par[N];

ll A, B, C, Hsh[N], P[N], dp[N][N]; /// dp -> how much we can save

string s;

inline ll get(ll l, ll r)
{
    return (Hsh[r] - (Hsh[l - 1] * P[r - l + 1] % mod) + mod) % mod;
}

int main()
{
	fast_io;
    for(int i = P[0] = 1; i < N; i ++) { P[i] = P[i - 1] * base % mod; }
    cin >> n >> s >> A >> B >> C;
    s = "." + s;
    for(int i = 1; i <= n; i ++) { Hsh[i] = (Hsh[i - 1] * base + s[i]) % mod; }
    for(int len = 1; len <= n; len ++)
    {
        memset(par, -1, sizeof par);
        vector < pll > vec;
        for(int i = len; i <= n; i ++)
        {
            vec.push_back(Mp(get(i - len + 1, i), i));
        }
        for(int i = 1; i <= n; i ++)
        {
            dp[i][i + len - 1] = max({dp[i][i + len - 1], dp[i + 1][i + len - 1], dp[i][i + len - 2]});
        }
        sort(all(vec));
        for(int i = len; i <= n; i ++)
        {
            ll cu = get(i - len + 1, i);
            int id = lower_bound(all(vec), Mp(cu, 1ll * i + len)) - vec.begin();
            if(id < SZ(vec) && vec[id].F == cu)
            {
                par[i] = vec[id].S;
            }
        }
        for(int i = len; i <= n; i ++)
        {
            int nxt = par[i], cnt = 1;
            ll cu = dp[i - len + 1][i];
            while(nxt != -1)
            {
                cnt ++;
                dp[i - len + 1][nxt] = max(dp[i - len + 1][nxt], cu + 1ll * len * (cnt - 1) * A - B - 1ll * cnt * C);
                nxt = par[nxt];
            }
        }
    }
    cout << 1ll * n * A - dp[1][n];
	return 0;
}

/* check corner case(n = 1?), watch for negetive index or overflow */
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 264 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 265 ms 33848 KB Output is correct
4 Correct 340 ms 38872 KB Output is correct
5 Correct 349 ms 42488 KB Output is correct
6 Correct 416 ms 45804 KB Output is correct
7 Correct 508 ms 49492 KB Output is correct
8 Correct 510 ms 49564 KB Output is correct
9 Correct 502 ms 49560 KB Output is correct
10 Correct 1 ms 340 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 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 488 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 264 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 1 ms 340 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 468 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 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 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 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 360 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 264 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 1 ms 340 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 468 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 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 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 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 360 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 724 KB Output is correct
41 Correct 2 ms 1364 KB Output is correct
42 Correct 3 ms 1364 KB Output is correct
43 Correct 3 ms 1364 KB Output is correct
44 Correct 3 ms 1492 KB Output is correct
45 Correct 4 ms 1364 KB Output is correct
46 Correct 3 ms 1364 KB Output is correct
47 Correct 4 ms 1492 KB Output is correct
48 Correct 5 ms 1364 KB Output is correct
49 Correct 4 ms 1364 KB Output is correct
50 Correct 4 ms 1492 KB Output is correct
51 Correct 4 ms 1492 KB Output is correct
52 Correct 5 ms 1460 KB Output is correct
53 Correct 3 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 264 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 1 ms 340 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 468 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 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 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 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 360 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 724 KB Output is correct
41 Correct 2 ms 1364 KB Output is correct
42 Correct 3 ms 1364 KB Output is correct
43 Correct 3 ms 1364 KB Output is correct
44 Correct 3 ms 1492 KB Output is correct
45 Correct 4 ms 1364 KB Output is correct
46 Correct 3 ms 1364 KB Output is correct
47 Correct 4 ms 1492 KB Output is correct
48 Correct 5 ms 1364 KB Output is correct
49 Correct 4 ms 1364 KB Output is correct
50 Correct 4 ms 1492 KB Output is correct
51 Correct 4 ms 1492 KB Output is correct
52 Correct 5 ms 1460 KB Output is correct
53 Correct 3 ms 1364 KB Output is correct
54 Correct 16 ms 3684 KB Output is correct
55 Correct 49 ms 12188 KB Output is correct
56 Correct 73 ms 12236 KB Output is correct
57 Correct 82 ms 12208 KB Output is correct
58 Correct 85 ms 12156 KB Output is correct
59 Correct 71 ms 12132 KB Output is correct
60 Correct 74 ms 12192 KB Output is correct
61 Correct 85 ms 12120 KB Output is correct
62 Correct 78 ms 12192 KB Output is correct
63 Correct 79 ms 12176 KB Output is correct
64 Correct 82 ms 12208 KB Output is correct
65 Correct 93 ms 12128 KB Output is correct
66 Correct 87 ms 12200 KB Output is correct
67 Correct 74 ms 12192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 264 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 265 ms 33848 KB Output is correct
14 Correct 340 ms 38872 KB Output is correct
15 Correct 349 ms 42488 KB Output is correct
16 Correct 416 ms 45804 KB Output is correct
17 Correct 508 ms 49492 KB Output is correct
18 Correct 510 ms 49564 KB Output is correct
19 Correct 502 ms 49560 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 488 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 360 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 1 ms 360 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 724 KB Output is correct
58 Correct 2 ms 1364 KB Output is correct
59 Correct 3 ms 1364 KB Output is correct
60 Correct 3 ms 1364 KB Output is correct
61 Correct 3 ms 1492 KB Output is correct
62 Correct 4 ms 1364 KB Output is correct
63 Correct 3 ms 1364 KB Output is correct
64 Correct 4 ms 1492 KB Output is correct
65 Correct 5 ms 1364 KB Output is correct
66 Correct 4 ms 1364 KB Output is correct
67 Correct 4 ms 1492 KB Output is correct
68 Correct 4 ms 1492 KB Output is correct
69 Correct 5 ms 1460 KB Output is correct
70 Correct 3 ms 1364 KB Output is correct
71 Correct 16 ms 3684 KB Output is correct
72 Correct 49 ms 12188 KB Output is correct
73 Correct 73 ms 12236 KB Output is correct
74 Correct 82 ms 12208 KB Output is correct
75 Correct 85 ms 12156 KB Output is correct
76 Correct 71 ms 12132 KB Output is correct
77 Correct 74 ms 12192 KB Output is correct
78 Correct 85 ms 12120 KB Output is correct
79 Correct 78 ms 12192 KB Output is correct
80 Correct 79 ms 12176 KB Output is correct
81 Correct 82 ms 12208 KB Output is correct
82 Correct 93 ms 12128 KB Output is correct
83 Correct 87 ms 12200 KB Output is correct
84 Correct 74 ms 12192 KB Output is correct
85 Correct 218 ms 26432 KB Output is correct
86 Correct 598 ms 49520 KB Output is correct
87 Correct 631 ms 49612 KB Output is correct
88 Correct 610 ms 49616 KB Output is correct
89 Correct 604 ms 49496 KB Output is correct
90 Incorrect 610 ms 49596 KB Output isn't correct
91 Halted 0 ms 0 KB -