답안 #548714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548714 2022-04-14T10:35:32 Z Ronin13 Copy and Paste 3 (JOI22_copypaste3) C++14
57 / 100
3000 ms 33748 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 + 1;
const int inf = 1e9 + 1;
const ll linf = 1e18 + 1;


ll h[NMAX];
const ll mod = 1e9 + 7;
const ll pr = 29;
ll po[NMAX];
string s;

void fil(){
    int n = s.size();
    h[0] = 0;
    for(int i = 1; i <= n; i++){
        ll x = s[i - 1] - 'a';
        h[i] = h[i - 1] * 29 + x;
        h[i] %= mod;
    }
}

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

ll cnt[2501][2501];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    po[0] = 1;
    for(int i = 1; i <= 2500; i++){
        po[i] = po[i - 1] * pr;
        po[i] %= mod;
    }
    int n; cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cnt[i][j] = linf;
        }
    }
    cin >> s;
    ll a, b, c; cin >> a >> b >> c;
    fil();
    for(int r = 1; r <= n; r++){
        pii dp[n + 1];
        for(int i = 1; i <= n;  i++){
            dp[i] = {inf, 0};
        }
        dp[1] = {r, 1};
        cnt[r][r] = a;
        for(int l = r - 1; l >= 1; l--){
            for(int sz = 1; sz <= r - l + 1; sz++){
                ll x = gethash(l, l + sz - 1);
                ll y = gethash(r - sz + 1, r);
                if(x == y){
                    if(dp[sz].f > l + sz - 1){
                        dp[sz].s++;
                        dp[sz].f = l;
                    }
                }
            }
            cnt[l][r] = cnt[l][r - 1] + a;
            for(int sz = 1; sz <= r - l + 1; sz++){
                ll m = dp[sz].s;
                ll val = cnt[r - sz + 1][r];
                cnt[l][r] = min(cnt[l][r], (c - sz * a) * m + (r - l + 1) * a + val + b);
            }
        }

    }
    /*for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(cnt[i][j] == linf)cout << - 1 << " ";
            else cout << cnt[i][j] << " ";
        }
        cout << "\n";
    }*/
    cout << cnt[1][n];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 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 0 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 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Execution timed out 3079 ms 33748 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 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 0 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 360 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 0 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 488 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 484 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 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 340 KB Output is correct
38 Correct 1 ms 356 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 0 ms 340 KB Output is correct
4 Correct 0 ms 340 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 0 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 360 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 0 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 488 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 484 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 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 340 KB Output is correct
38 Correct 1 ms 356 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 724 KB Output is correct
41 Correct 11 ms 1468 KB Output is correct
42 Correct 11 ms 1364 KB Output is correct
43 Correct 11 ms 1472 KB Output is correct
44 Correct 12 ms 1376 KB Output is correct
45 Correct 12 ms 1472 KB Output is correct
46 Correct 14 ms 1468 KB Output is correct
47 Correct 11 ms 1472 KB Output is correct
48 Correct 11 ms 1364 KB Output is correct
49 Correct 11 ms 1364 KB Output is correct
50 Correct 14 ms 1476 KB Output is correct
51 Correct 11 ms 1476 KB Output is correct
52 Correct 11 ms 1364 KB Output is correct
53 Correct 11 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 0 ms 340 KB Output is correct
4 Correct 0 ms 340 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 0 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 360 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 0 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 488 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 484 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 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 340 KB Output is correct
38 Correct 1 ms 356 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 724 KB Output is correct
41 Correct 11 ms 1468 KB Output is correct
42 Correct 11 ms 1364 KB Output is correct
43 Correct 11 ms 1472 KB Output is correct
44 Correct 12 ms 1376 KB Output is correct
45 Correct 12 ms 1472 KB Output is correct
46 Correct 14 ms 1468 KB Output is correct
47 Correct 11 ms 1472 KB Output is correct
48 Correct 11 ms 1364 KB Output is correct
49 Correct 11 ms 1364 KB Output is correct
50 Correct 14 ms 1476 KB Output is correct
51 Correct 11 ms 1476 KB Output is correct
52 Correct 11 ms 1364 KB Output is correct
53 Correct 11 ms 1364 KB Output is correct
54 Correct 110 ms 3708 KB Output is correct
55 Correct 1167 ms 12188 KB Output is correct
56 Correct 1165 ms 12196 KB Output is correct
57 Correct 1150 ms 12192 KB Output is correct
58 Correct 1181 ms 12188 KB Output is correct
59 Correct 1159 ms 12236 KB Output is correct
60 Correct 1166 ms 12188 KB Output is correct
61 Correct 1169 ms 12200 KB Output is correct
62 Correct 1174 ms 12236 KB Output is correct
63 Correct 1164 ms 12184 KB Output is correct
64 Correct 1158 ms 12184 KB Output is correct
65 Correct 1202 ms 12192 KB Output is correct
66 Correct 1202 ms 12188 KB Output is correct
67 Correct 1152 ms 12200 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 0 ms 340 KB Output is correct
4 Correct 0 ms 340 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 0 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 344 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Execution timed out 3079 ms 33748 KB Time limit exceeded
14 Halted 0 ms 0 KB -