답안 #1004749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1004749 2024-06-21T13:36:47 Z tvladm2009 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
1128 ms 85332 KB
// https://oj.uz/submission/945391
#include <iostream> // am bagat o simulare mai demult pe vjudge si am bagat pb asta, o trimit si de pe main
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 543 ms 62808 KB Output is correct
4 Correct 620 ms 66900 KB Output is correct
5 Correct 739 ms 74076 KB Output is correct
6 Correct 924 ms 80976 KB Output is correct
7 Correct 1116 ms 85072 KB Output is correct
8 Correct 1128 ms 85332 KB Output is correct
9 Correct 1087 ms 85084 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 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 0 ms 2396 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 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 2396 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
25 Correct 0 ms 2652 KB Output is correct
26 Correct 0 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 0 ms 2652 KB Output is correct
31 Correct 0 ms 2652 KB Output is correct
32 Correct 0 ms 2652 KB Output is correct
33 Correct 1 ms 2508 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 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 2396 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
25 Correct 0 ms 2652 KB Output is correct
26 Correct 0 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 0 ms 2652 KB Output is correct
31 Correct 0 ms 2652 KB Output is correct
32 Correct 0 ms 2652 KB Output is correct
33 Correct 1 ms 2508 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 3 ms 5464 KB Output is correct
42 Correct 2 ms 5464 KB Output is correct
43 Correct 2 ms 5584 KB Output is correct
44 Correct 2 ms 5580 KB Output is correct
45 Correct 2 ms 5468 KB Output is correct
46 Correct 2 ms 5468 KB Output is correct
47 Correct 3 ms 5580 KB Output is correct
48 Correct 2 ms 5468 KB Output is correct
49 Correct 2 ms 5468 KB Output is correct
50 Correct 2 ms 5580 KB Output is correct
51 Correct 3 ms 5464 KB Output is correct
52 Correct 3 ms 5468 KB Output is correct
53 Correct 2 ms 5468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 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 2396 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 0 ms 2652 KB Output is correct
25 Correct 0 ms 2652 KB Output is correct
26 Correct 0 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 0 ms 2652 KB Output is correct
31 Correct 0 ms 2652 KB Output is correct
32 Correct 0 ms 2652 KB Output is correct
33 Correct 1 ms 2508 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 3 ms 5464 KB Output is correct
42 Correct 2 ms 5464 KB Output is correct
43 Correct 2 ms 5584 KB Output is correct
44 Correct 2 ms 5580 KB Output is correct
45 Correct 2 ms 5468 KB Output is correct
46 Correct 2 ms 5468 KB Output is correct
47 Correct 3 ms 5580 KB Output is correct
48 Correct 2 ms 5468 KB Output is correct
49 Correct 2 ms 5468 KB Output is correct
50 Correct 2 ms 5580 KB Output is correct
51 Correct 3 ms 5464 KB Output is correct
52 Correct 3 ms 5468 KB Output is correct
53 Correct 2 ms 5468 KB Output is correct
54 Correct 9 ms 14936 KB Output is correct
55 Correct 137 ms 31436 KB Output is correct
56 Correct 45 ms 31324 KB Output is correct
57 Correct 45 ms 31324 KB Output is correct
58 Correct 40 ms 31320 KB Output is correct
59 Correct 39 ms 31320 KB Output is correct
60 Correct 40 ms 31568 KB Output is correct
61 Correct 59 ms 31320 KB Output is correct
62 Correct 81 ms 31324 KB Output is correct
63 Correct 58 ms 31316 KB Output is correct
64 Correct 55 ms 31440 KB Output is correct
65 Correct 77 ms 31444 KB Output is correct
66 Correct 73 ms 31324 KB Output is correct
67 Correct 38 ms 31324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 543 ms 62808 KB Output is correct
14 Correct 620 ms 66900 KB Output is correct
15 Correct 739 ms 74076 KB Output is correct
16 Correct 924 ms 80976 KB Output is correct
17 Correct 1116 ms 85072 KB Output is correct
18 Correct 1128 ms 85332 KB Output is correct
19 Correct 1087 ms 85084 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 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 0 ms 2396 KB Output is correct
26 Correct 0 ms 2652 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 0 ms 2392 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 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 2396 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 0 ms 2652 KB Output is correct
42 Correct 0 ms 2652 KB Output is correct
43 Correct 0 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 0 ms 2652 KB Output is correct
48 Correct 0 ms 2652 KB Output is correct
49 Correct 0 ms 2652 KB Output is correct
50 Correct 1 ms 2508 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 1 ms 2904 KB Output is correct
58 Correct 3 ms 5464 KB Output is correct
59 Correct 2 ms 5464 KB Output is correct
60 Correct 2 ms 5584 KB Output is correct
61 Correct 2 ms 5580 KB Output is correct
62 Correct 2 ms 5468 KB Output is correct
63 Correct 2 ms 5468 KB Output is correct
64 Correct 3 ms 5580 KB Output is correct
65 Correct 2 ms 5468 KB Output is correct
66 Correct 2 ms 5468 KB Output is correct
67 Correct 2 ms 5580 KB Output is correct
68 Correct 3 ms 5464 KB Output is correct
69 Correct 3 ms 5468 KB Output is correct
70 Correct 2 ms 5468 KB Output is correct
71 Correct 9 ms 14936 KB Output is correct
72 Correct 137 ms 31436 KB Output is correct
73 Correct 45 ms 31324 KB Output is correct
74 Correct 45 ms 31324 KB Output is correct
75 Correct 40 ms 31320 KB Output is correct
76 Correct 39 ms 31320 KB Output is correct
77 Correct 40 ms 31568 KB Output is correct
78 Correct 59 ms 31320 KB Output is correct
79 Correct 81 ms 31324 KB Output is correct
80 Correct 58 ms 31316 KB Output is correct
81 Correct 55 ms 31440 KB Output is correct
82 Correct 77 ms 31444 KB Output is correct
83 Correct 73 ms 31324 KB Output is correct
84 Correct 38 ms 31324 KB Output is correct
85 Correct 119 ms 54108 KB Output is correct
86 Correct 364 ms 85080 KB Output is correct
87 Correct 312 ms 85244 KB Output is correct
88 Correct 294 ms 85080 KB Output is correct
89 Correct 272 ms 85072 KB Output is correct
90 Correct 287 ms 85240 KB Output is correct
91 Correct 440 ms 85332 KB Output is correct
92 Correct 521 ms 85160 KB Output is correct
93 Correct 333 ms 85072 KB Output is correct
94 Correct 344 ms 85256 KB Output is correct
95 Correct 497 ms 85124 KB Output is correct
96 Correct 515 ms 85236 KB Output is correct
97 Correct 258 ms 85240 KB Output is correct