답안 #549233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549233 2022-04-15T12:24:50 Z Ronin13 Copy and Paste 3 (JOI22_copypaste3) C++14
30 / 100
1002 ms 83928 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

const int NMAX = 2501;
const int inf = 1e9 + 1;
const ll linf = 1e18 + 1;
ll mod[] ={1000000009, 1000000009, 998244353};
ll pr[] = {37, 31, 37};

ll po[NMAX][3];
ll h[NMAX][3];

void hashing(string s){
    h[0][0] = 0;
    h[0][1] = 0;
    h[0][2] = 0;
    int n = s.size();
    for(int i = 1; i <= n; i++){
        ll x = s[i - 1] - 'a' + 1;
        for(int j = 0; j < 3; j++){
            h[i][j] = h[i - 1][j] * pr[j] + x;
            h[i][j] %= mod[j];
        }
    }
}

int get(int l, int r, int ind){
    ll x = h[r][ind] - h[l - 1][ind] * po[r - l + 1][ind];
    x %= mod[ind];
    x += mod[ind];
    x %= mod[ind];
    return x;
}

ll dp[NMAX][NMAX];
int adj[NMAX][NMAX];

unordered_map<int, int> mp;
vector <int> vec[NMAX];

int main(){
    po[0][0] = po[0][1] = po[0][2] = 1;
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for(int k = 0; k < 3; k++){
    for(int i = 1; i <=n; i++){
        po[i][k] = po[i - 1][k] * pr[k];
        po[i][k] %= mod[k];
    }
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = linf;
        }
    }
    string s; cin >> s;
    ll a, b, c;
    cin >> a >> b >> c;
    hashing(s);
    for(int i = 1; i <= n; i++){
        for(auto to : vec[i - 1]) mp[to] = i - 1;
        for(int j = i; j <= n; j++){
            int x = get(i, j, 0);
           // int x1 = get(i, j, 1);
            int v = mp[x];
            if(v != 0)
            adj[i][j - i + 1] = v - (j - i);
            vec[j].pb(x);
        }
    }
    /*for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cout << adj[i][j] << ' ';
        }
        cout << "\n";
    }*/
    vector <int> v[NMAX];
    ll cnt[n + 1];
    for(ll r = 1; r <= n; r++){
        for(int i = 1; i <= n; i++)v[i].clear();
        for(int i = 0; i <= n; i++)cnt[i] = 0;
        for(int i = 1; i <= r; i++){
            int cur = r - i + 1;
            while(cur){
                v[cur].pb(i);
                cur = adj[cur][i];
            }
        }
        ll mn = 0;
        dp[r][r] = a;
        for(ll l = r; l >= 1; l--){
            for(int to : v[l]){
                cnt[to]++;
                ll val = dp[r - to + 1][r] + b;
                val += (c - (ll)to * a) * cnt[to];
                mn = min(mn, val);
            }
            dp[l][r] = mn + (r - l + 1) * a;
            dp[l][r] = min(dp[l][r], dp[l][r - 1] + a);
        }
    }
    /*for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(dp[i][j] == linf) cout << "-1 ";
            else cout << dp[i][j] << " ";
        }
        cout << "\n";
    }*/
    cout << dp[1][n];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 497 ms 54224 KB Output is correct
4 Correct 536 ms 61824 KB Output is correct
5 Correct 722 ms 68284 KB Output is correct
6 Correct 828 ms 75836 KB Output is correct
7 Correct 1002 ms 83868 KB Output is correct
8 Correct 931 ms 83928 KB Output is correct
9 Correct 992 ms 83928 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 444 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 444 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 0 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 700 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 704 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 452 KB Output is correct
35 Correct 1 ms 440 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 1 ms 444 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 0 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 700 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 704 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 452 KB Output is correct
35 Correct 1 ms 440 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 1 ms 444 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 2 ms 1364 KB Output is correct
41 Correct 5 ms 2516 KB Output is correct
42 Correct 6 ms 3284 KB Output is correct
43 Correct 7 ms 3264 KB Output is correct
44 Correct 6 ms 3308 KB Output is correct
45 Correct 6 ms 3184 KB Output is correct
46 Correct 5 ms 3156 KB Output is correct
47 Correct 4 ms 2644 KB Output is correct
48 Correct 6 ms 2924 KB Output is correct
49 Correct 5 ms 3028 KB Output is correct
50 Correct 6 ms 3028 KB Output is correct
51 Correct 5 ms 3028 KB Output is correct
52 Correct 5 ms 3028 KB Output is correct
53 Correct 5 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 0 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 700 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 704 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 452 KB Output is correct
35 Correct 1 ms 440 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 1 ms 444 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 2 ms 1364 KB Output is correct
41 Correct 5 ms 2516 KB Output is correct
42 Correct 6 ms 3284 KB Output is correct
43 Correct 7 ms 3264 KB Output is correct
44 Correct 6 ms 3308 KB Output is correct
45 Correct 6 ms 3184 KB Output is correct
46 Correct 5 ms 3156 KB Output is correct
47 Correct 4 ms 2644 KB Output is correct
48 Correct 6 ms 2924 KB Output is correct
49 Correct 5 ms 3028 KB Output is correct
50 Correct 6 ms 3028 KB Output is correct
51 Correct 5 ms 3028 KB Output is correct
52 Correct 5 ms 3028 KB Output is correct
53 Correct 5 ms 3156 KB Output is correct
54 Correct 36 ms 10552 KB Output is correct
55 Correct 122 ms 20116 KB Output is correct
56 Runtime error 306 ms 81164 KB Execution killed with signal 11
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 497 ms 54224 KB Output is correct
14 Correct 536 ms 61824 KB Output is correct
15 Correct 722 ms 68284 KB Output is correct
16 Correct 828 ms 75836 KB Output is correct
17 Correct 1002 ms 83868 KB Output is correct
18 Correct 931 ms 83928 KB Output is correct
19 Correct 992 ms 83928 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 444 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 444 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 0 ms 468 KB Output is correct
38 Correct 1 ms 724 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 1 ms 724 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 0 ms 596 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 700 KB Output is correct
47 Correct 1 ms 724 KB Output is correct
48 Correct 1 ms 704 KB Output is correct
49 Correct 1 ms 596 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 1 ms 452 KB Output is correct
52 Correct 1 ms 440 KB Output is correct
53 Correct 0 ms 468 KB Output is correct
54 Correct 1 ms 444 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 724 KB Output is correct
57 Correct 2 ms 1364 KB Output is correct
58 Correct 5 ms 2516 KB Output is correct
59 Correct 6 ms 3284 KB Output is correct
60 Correct 7 ms 3264 KB Output is correct
61 Correct 6 ms 3308 KB Output is correct
62 Correct 6 ms 3184 KB Output is correct
63 Correct 5 ms 3156 KB Output is correct
64 Correct 4 ms 2644 KB Output is correct
65 Correct 6 ms 2924 KB Output is correct
66 Correct 5 ms 3028 KB Output is correct
67 Correct 6 ms 3028 KB Output is correct
68 Correct 5 ms 3028 KB Output is correct
69 Correct 5 ms 3028 KB Output is correct
70 Correct 5 ms 3156 KB Output is correct
71 Correct 36 ms 10552 KB Output is correct
72 Correct 122 ms 20116 KB Output is correct
73 Runtime error 306 ms 81164 KB Execution killed with signal 11
74 Halted 0 ms 0 KB -