Submission #945391

# Submission time Handle Problem Language Result Execution time Memory
945391 2024-03-13T17:29:13 Z vjudge1 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
1270 ms 85332 KB
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";
const int MAXN = 2500 + 7;
const ll inf = 1e18;
const ll Mod = (1LL << 61) - 1;

ll n, a, b, c;
string s;
ll hsh[MAXN][MAXN];
ll dp[MAXN][MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME);
    cin >> n >> s >> a >> b >> c;
    s = "#" + s;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            hsh[i][j] = (hsh[i][j - 1] * 26 + s[j] - 'a') % Mod;
            dp[i][j] = inf;
        }
        dp[i][i] = a;
    }
    for (int h = 1; h <= n; h++) {
        vector<pair<ll, int>> cand;
        for (int i = 1; i + h - 1 <= n; i++) {
            int j = i + h - 1;
            chkmin(dp[i][j], min(dp[i + 1][j], dp[i][j - 1]) + a);
            cand.pb(mp(hsh[i][j], i));
        }
        sort(all(cand));
        for (auto it: cand) {
            int x = 1;
            int i = it.second;
            while (true) {
                int pos = lower_bound(all(cand), mp(it.first, i + h)) - cand.begin();
                if (pos < sz(cand) && cand[pos].first == it.first) {
                    i = cand[pos].second;
                    x++;
                    chkmin(dp[it.second][i + h - 1], dp[it.second][it.second + h - 1] + b + c * x + a * (i + h - it.second - x * h));
                } else {
                    break;
                }
            }
        }
    }
    cout << dp[1][n] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 607 ms 63032 KB Output is correct
4 Correct 760 ms 66932 KB Output is correct
5 Correct 871 ms 74276 KB Output is correct
6 Correct 1041 ms 81000 KB Output is correct
7 Correct 1254 ms 85240 KB Output is correct
8 Correct 1270 ms 85244 KB Output is correct
9 Correct 1239 ms 85244 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 460 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2508 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 460 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2508 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2908 KB Output is correct
41 Correct 4 ms 5468 KB Output is correct
42 Correct 3 ms 5468 KB Output is correct
43 Correct 3 ms 5468 KB Output is correct
44 Correct 3 ms 5468 KB Output is correct
45 Correct 2 ms 5468 KB Output is correct
46 Correct 2 ms 5464 KB Output is correct
47 Correct 4 ms 5584 KB Output is correct
48 Correct 3 ms 5720 KB Output is correct
49 Correct 3 ms 5468 KB Output is correct
50 Correct 3 ms 5468 KB Output is correct
51 Correct 4 ms 5468 KB Output is correct
52 Correct 4 ms 5468 KB Output is correct
53 Correct 2 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 460 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2508 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2908 KB Output is correct
41 Correct 4 ms 5468 KB Output is correct
42 Correct 3 ms 5468 KB Output is correct
43 Correct 3 ms 5468 KB Output is correct
44 Correct 3 ms 5468 KB Output is correct
45 Correct 2 ms 5468 KB Output is correct
46 Correct 2 ms 5464 KB Output is correct
47 Correct 4 ms 5584 KB Output is correct
48 Correct 3 ms 5720 KB Output is correct
49 Correct 3 ms 5468 KB Output is correct
50 Correct 3 ms 5468 KB Output is correct
51 Correct 4 ms 5468 KB Output is correct
52 Correct 4 ms 5468 KB Output is correct
53 Correct 2 ms 5468 KB Output is correct
54 Correct 12 ms 14792 KB Output is correct
55 Correct 137 ms 31440 KB Output is correct
56 Correct 68 ms 31440 KB Output is correct
57 Correct 56 ms 31320 KB Output is correct
58 Correct 57 ms 31440 KB Output is correct
59 Correct 52 ms 31320 KB Output is correct
60 Correct 51 ms 31324 KB Output is correct
61 Correct 73 ms 31324 KB Output is correct
62 Correct 106 ms 31324 KB Output is correct
63 Correct 70 ms 31688 KB Output is correct
64 Correct 72 ms 31324 KB Output is correct
65 Correct 94 ms 31324 KB Output is correct
66 Correct 89 ms 31440 KB Output is correct
67 Correct 54 ms 31440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 607 ms 63032 KB Output is correct
14 Correct 760 ms 66932 KB Output is correct
15 Correct 871 ms 74276 KB Output is correct
16 Correct 1041 ms 81000 KB Output is correct
17 Correct 1254 ms 85240 KB Output is correct
18 Correct 1270 ms 85244 KB Output is correct
19 Correct 1239 ms 85244 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2652 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 460 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 2508 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 1 ms 2908 KB Output is correct
58 Correct 4 ms 5468 KB Output is correct
59 Correct 3 ms 5468 KB Output is correct
60 Correct 3 ms 5468 KB Output is correct
61 Correct 3 ms 5468 KB Output is correct
62 Correct 2 ms 5468 KB Output is correct
63 Correct 2 ms 5464 KB Output is correct
64 Correct 4 ms 5584 KB Output is correct
65 Correct 3 ms 5720 KB Output is correct
66 Correct 3 ms 5468 KB Output is correct
67 Correct 3 ms 5468 KB Output is correct
68 Correct 4 ms 5468 KB Output is correct
69 Correct 4 ms 5468 KB Output is correct
70 Correct 2 ms 5468 KB Output is correct
71 Correct 12 ms 14792 KB Output is correct
72 Correct 137 ms 31440 KB Output is correct
73 Correct 68 ms 31440 KB Output is correct
74 Correct 56 ms 31320 KB Output is correct
75 Correct 57 ms 31440 KB Output is correct
76 Correct 52 ms 31320 KB Output is correct
77 Correct 51 ms 31324 KB Output is correct
78 Correct 73 ms 31324 KB Output is correct
79 Correct 106 ms 31324 KB Output is correct
80 Correct 70 ms 31688 KB Output is correct
81 Correct 72 ms 31324 KB Output is correct
82 Correct 94 ms 31324 KB Output is correct
83 Correct 89 ms 31440 KB Output is correct
84 Correct 54 ms 31440 KB Output is correct
85 Correct 181 ms 54172 KB Output is correct
86 Correct 424 ms 85240 KB Output is correct
87 Correct 391 ms 85236 KB Output is correct
88 Correct 357 ms 85236 KB Output is correct
89 Correct 367 ms 85332 KB Output is correct
90 Correct 341 ms 85104 KB Output is correct
91 Correct 611 ms 85332 KB Output is correct
92 Correct 751 ms 85240 KB Output is correct
93 Correct 443 ms 85240 KB Output is correct
94 Correct 478 ms 85084 KB Output is correct
95 Correct 734 ms 85332 KB Output is correct
96 Correct 727 ms 85332 KB Output is correct
97 Correct 346 ms 85076 KB Output is correct