답안 #843549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
843549 2023-09-04T04:51:10 Z Cookie Copy and Paste 3 (JOI22_copypaste3) C++14
30 / 100
268 ms 73040 KB
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>

const int mxn = 2505;
const ll inf = 1e18, mod = 1e9 + 7;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rr(ll l, ll r){
    return(uniform_int_distribution<ll>(l, r)(rng));
}

ll n, a, b, c;
string s;
ll dp[mxn + 1][mxn + 1], hsh[mxn + 1], pw[mxn + 1];
int z[2505], nxt[2505][2505];
void ckmin(ll &a, ll b){
    a = min(a, b);
}
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> s >> a >> b >> c; 
    for(int i = 0; i < n; i++){
        int l = i, r = i;
        for(int j = i + 1; j < n; j++){
            if(j > r){
                l = r = j;
                while(r < n && s[r] == s[r - l + i])r++;
                z[j] = r - l; r--;
            }else{
                int pos = j - l;
                if(z[pos] < r - j + 1)z[j] = z[pos];
                else{
                    l = j;
                    while(r < n && s[r] == s[r - l + i])r++;
                    z[j] = r - l; r--;
                }
            }
        }
        int rp = i + 1;
        for(int j = 1; j <= n; j++){
            rp = max(rp, i + j);
            while(rp < n && z[rp] < j){
                rp++;
            }
            if(rp < n)nxt[i + 1][j] = rp + 1;
            else nxt[i + 1][j] = -1;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j++){
            dp[i][j] = inf;
        }
    }
    for(int len = 1; len <= n; len++){
        
        for(int i = 1; i + len - 1 <= n; i++){
            int l = i, r = i + len - 1;
            ckmin(dp[l][r], dp[l + 1][r] + a); ckmin(dp[l][r], dp[l][r - 1] + a);
            
           
            int idl = l, cnt = 1;
            while(nxt[idl][len] != -1){
                idl = nxt[idl][len];
                cnt++;
                int nwr = idl + len - 1;
                ckmin(dp[l][nwr], dp[l][r] + b + c * cnt + a * (nwr - l + 1 - len * cnt));
            }
            
        }
        
    }
    cout << dp[1][n];
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2392 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 0 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 117 ms 58248 KB Output is correct
4 Correct 149 ms 62288 KB Output is correct
5 Correct 184 ms 68176 KB Output is correct
6 Correct 229 ms 72432 KB Output is correct
7 Correct 264 ms 72816 KB Output is correct
8 Correct 268 ms 73040 KB Output is correct
9 Correct 262 ms 72812 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2392 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 0 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 6488 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 4440 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 6488 KB Output is correct
22 Correct 1 ms 6488 KB Output is correct
23 Correct 1 ms 6488 KB Output is correct
24 Correct 1 ms 6488 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 6488 KB Output is correct
28 Correct 1 ms 6488 KB Output is correct
29 Correct 1 ms 6488 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 6488 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 0 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2392 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 0 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 6488 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 4440 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 6488 KB Output is correct
22 Correct 1 ms 6488 KB Output is correct
23 Correct 1 ms 6488 KB Output is correct
24 Correct 1 ms 6488 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 6488 KB Output is correct
28 Correct 1 ms 6488 KB Output is correct
29 Correct 1 ms 6488 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 6488 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 0 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 6488 KB Output is correct
40 Correct 1 ms 6488 KB Output is correct
41 Correct 2 ms 8536 KB Output is correct
42 Correct 2 ms 8536 KB Output is correct
43 Correct 1 ms 8536 KB Output is correct
44 Correct 1 ms 8536 KB Output is correct
45 Correct 1 ms 8540 KB Output is correct
46 Correct 1 ms 8536 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 8536 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
51 Correct 1 ms 8536 KB Output is correct
52 Correct 1 ms 8536 KB Output is correct
53 Correct 1 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2392 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 0 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 6488 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 4440 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 6488 KB Output is correct
22 Correct 1 ms 6488 KB Output is correct
23 Correct 1 ms 6488 KB Output is correct
24 Correct 1 ms 6488 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 6488 KB Output is correct
28 Correct 1 ms 6488 KB Output is correct
29 Correct 1 ms 6488 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 6488 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 0 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 6488 KB Output is correct
40 Correct 1 ms 6488 KB Output is correct
41 Correct 2 ms 8536 KB Output is correct
42 Correct 2 ms 8536 KB Output is correct
43 Correct 1 ms 8536 KB Output is correct
44 Correct 1 ms 8536 KB Output is correct
45 Correct 1 ms 8540 KB Output is correct
46 Correct 1 ms 8536 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 8536 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
51 Correct 1 ms 8536 KB Output is correct
52 Correct 1 ms 8536 KB Output is correct
53 Correct 1 ms 8536 KB Output is correct
54 Correct 4 ms 18776 KB Output is correct
55 Correct 24 ms 33368 KB Output is correct
56 Correct 13 ms 33372 KB Output is correct
57 Correct 11 ms 33372 KB Output is correct
58 Correct 10 ms 33368 KB Output is correct
59 Correct 9 ms 33368 KB Output is correct
60 Correct 9 ms 33368 KB Output is correct
61 Correct 10 ms 33368 KB Output is correct
62 Incorrect 12 ms 33368 KB Output isn't correct
63 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2392 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 0 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 117 ms 58248 KB Output is correct
14 Correct 149 ms 62288 KB Output is correct
15 Correct 184 ms 68176 KB Output is correct
16 Correct 229 ms 72432 KB Output is correct
17 Correct 264 ms 72816 KB Output is correct
18 Correct 268 ms 73040 KB Output is correct
19 Correct 262 ms 72812 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 6488 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 4440 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 6488 KB Output is correct
39 Correct 1 ms 6488 KB Output is correct
40 Correct 1 ms 6488 KB Output is correct
41 Correct 1 ms 6488 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 6488 KB Output is correct
45 Correct 1 ms 6488 KB Output is correct
46 Correct 1 ms 6488 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6488 KB Output is correct
49 Correct 1 ms 6488 KB Output is correct
50 Correct 1 ms 6488 KB Output is correct
51 Correct 1 ms 2392 KB Output is correct
52 Correct 0 ms 2392 KB Output is correct
53 Correct 0 ms 2392 KB Output is correct
54 Correct 1 ms 2392 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 6488 KB Output is correct
57 Correct 1 ms 6488 KB Output is correct
58 Correct 2 ms 8536 KB Output is correct
59 Correct 2 ms 8536 KB Output is correct
60 Correct 1 ms 8536 KB Output is correct
61 Correct 1 ms 8536 KB Output is correct
62 Correct 1 ms 8540 KB Output is correct
63 Correct 1 ms 8536 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 8536 KB Output is correct
67 Correct 1 ms 8540 KB Output is correct
68 Correct 1 ms 8536 KB Output is correct
69 Correct 1 ms 8536 KB Output is correct
70 Correct 1 ms 8536 KB Output is correct
71 Correct 4 ms 18776 KB Output is correct
72 Correct 24 ms 33368 KB Output is correct
73 Correct 13 ms 33372 KB Output is correct
74 Correct 11 ms 33372 KB Output is correct
75 Correct 10 ms 33368 KB Output is correct
76 Correct 9 ms 33368 KB Output is correct
77 Correct 9 ms 33368 KB Output is correct
78 Correct 10 ms 33368 KB Output is correct
79 Incorrect 12 ms 33368 KB Output isn't correct
80 Halted 0 ms 0 KB -