Submission #591866

# Submission time Handle Problem Language Result Execution time Memory
591866 2022-07-08T05:18:07 Z 이동현(#8425) Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
1155 ms 84712 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

int pre[2504][2504];
long long dp[2504][2504];

int pw(int x, int y, int mod){
    if(!y) return 1;
    int gop = 1;
    if(y % 2){
        gop = x;
        y -= 1;
    }
    int val = pw(x, y / 2, mod);
    return (long long)val * val % mod * gop % mod;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(pre, -1, sizeof(pre));
    int n; cin >> n;
    string s; cin >> s;
    int a, b, c; cin >> a >> b >> c;
    int p = 998244353, mod = (int)1e9 + 7;
    int invp = pw(p, mod - 2, mod);
    for(int i = 1; i <= n; ++i){
        int pi = 1;
        for(int j = 0; j < i; ++j){
            pi = (long long)pi * p % mod;
        }
        int now = 0;
        for(int j = i - 1; j >= 0; --j){
            now = (long long)now * p % mod;
            now = ((long long)now + s[j] - 'a') % mod;
        }
        unordered_map<int, deque<int>> pos;
        for(int j = 0; j + i - 1 < n; ++j){
            auto&nowp = pos[now];
            while((int)nowp.size() >= 2 && nowp[1] + i <= j){
                nowp.pop_front();
            }
            if((int)nowp.size() && nowp[0] + i <= j){
                pre[j][i] = nowp[0];
            }
            nowp.push_back(j);
            if(j + i < n){
                now = ((long long)now + (long long)pi * (s[j + i] - 'a') % mod) % mod;
                now = ((long long)now - s[j] + 'a' + mod) % mod;
                now = (long long)now * invp % mod;
            }
        }
    }
    for(int j = 0; j < n; ++j){
        long long mnval = (long long)1e18;
        vector<long long> mnadd(n, (long long)1e18);
        for(int i = j; i >= 0; --i){
            if(i == j){
                dp[i][j] = a;
            }
            else{
                dp[i][j] = dp[i][j - 1] + a;
            }
            mnval = min(mnval, mnadd[i]);
            dp[i][j] = min(dp[i][j], mnval - (long long)a * i);
            long long cnt = 0;
            for(int k = i; k != -1; k = pre[k][j - i + 1]){
                ++cnt;
                mnadd[k] = min(mnadd[k], dp[i][j] + b + cnt * c + a * (j - k + 1 - cnt * (j - i + 1)) + (long long)k * a);
            }
        }
    }
    cout << dp[0][n - 1] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 49364 KB Output is correct
2 Correct 21 ms 49284 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 19 ms 49356 KB Output is correct
5 Correct 23 ms 49304 KB Output is correct
6 Correct 19 ms 49364 KB Output is correct
7 Correct 18 ms 49408 KB Output is correct
8 Correct 18 ms 49420 KB Output is correct
9 Correct 18 ms 49364 KB Output is correct
10 Correct 20 ms 49404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 49436 KB Output is correct
2 Correct 22 ms 49340 KB Output is correct
3 Correct 314 ms 69768 KB Output is correct
4 Correct 392 ms 72684 KB Output is correct
5 Correct 454 ms 75836 KB Output is correct
6 Correct 544 ms 79268 KB Output is correct
7 Correct 666 ms 82812 KB Output is correct
8 Correct 699 ms 82840 KB Output is correct
9 Correct 661 ms 82916 KB Output is correct
10 Correct 19 ms 49376 KB Output is correct
11 Correct 19 ms 49392 KB Output is correct
12 Correct 18 ms 49416 KB Output is correct
13 Correct 22 ms 49328 KB Output is correct
14 Correct 19 ms 49364 KB Output is correct
15 Correct 20 ms 49404 KB Output is correct
16 Correct 19 ms 49484 KB Output is correct
17 Correct 18 ms 49376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 49364 KB Output is correct
2 Correct 21 ms 49284 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 19 ms 49356 KB Output is correct
5 Correct 23 ms 49304 KB Output is correct
6 Correct 19 ms 49364 KB Output is correct
7 Correct 18 ms 49408 KB Output is correct
8 Correct 18 ms 49420 KB Output is correct
9 Correct 18 ms 49364 KB Output is correct
10 Correct 20 ms 49404 KB Output is correct
11 Correct 18 ms 49364 KB Output is correct
12 Correct 18 ms 49384 KB Output is correct
13 Correct 19 ms 49364 KB Output is correct
14 Correct 19 ms 49364 KB Output is correct
15 Correct 22 ms 49492 KB Output is correct
16 Correct 21 ms 49492 KB Output is correct
17 Correct 19 ms 49416 KB Output is correct
18 Correct 20 ms 49320 KB Output is correct
19 Correct 19 ms 49380 KB Output is correct
20 Correct 20 ms 49348 KB Output is correct
21 Correct 22 ms 49492 KB Output is correct
22 Correct 24 ms 49492 KB Output is correct
23 Correct 23 ms 49468 KB Output is correct
24 Correct 22 ms 49492 KB Output is correct
25 Correct 19 ms 49460 KB Output is correct
26 Correct 19 ms 49492 KB Output is correct
27 Correct 19 ms 49492 KB Output is correct
28 Correct 19 ms 49492 KB Output is correct
29 Correct 20 ms 49524 KB Output is correct
30 Correct 19 ms 49488 KB Output is correct
31 Correct 18 ms 49440 KB Output is correct
32 Correct 21 ms 49416 KB Output is correct
33 Correct 19 ms 49516 KB Output is correct
34 Correct 22 ms 49272 KB Output is correct
35 Correct 23 ms 49368 KB Output is correct
36 Correct 24 ms 49392 KB Output is correct
37 Correct 19 ms 49364 KB Output is correct
38 Correct 21 ms 49400 KB Output is correct
39 Correct 19 ms 49484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 49364 KB Output is correct
2 Correct 21 ms 49284 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 19 ms 49356 KB Output is correct
5 Correct 23 ms 49304 KB Output is correct
6 Correct 19 ms 49364 KB Output is correct
7 Correct 18 ms 49408 KB Output is correct
8 Correct 18 ms 49420 KB Output is correct
9 Correct 18 ms 49364 KB Output is correct
10 Correct 20 ms 49404 KB Output is correct
11 Correct 18 ms 49364 KB Output is correct
12 Correct 18 ms 49384 KB Output is correct
13 Correct 19 ms 49364 KB Output is correct
14 Correct 19 ms 49364 KB Output is correct
15 Correct 22 ms 49492 KB Output is correct
16 Correct 21 ms 49492 KB Output is correct
17 Correct 19 ms 49416 KB Output is correct
18 Correct 20 ms 49320 KB Output is correct
19 Correct 19 ms 49380 KB Output is correct
20 Correct 20 ms 49348 KB Output is correct
21 Correct 22 ms 49492 KB Output is correct
22 Correct 24 ms 49492 KB Output is correct
23 Correct 23 ms 49468 KB Output is correct
24 Correct 22 ms 49492 KB Output is correct
25 Correct 19 ms 49460 KB Output is correct
26 Correct 19 ms 49492 KB Output is correct
27 Correct 19 ms 49492 KB Output is correct
28 Correct 19 ms 49492 KB Output is correct
29 Correct 20 ms 49524 KB Output is correct
30 Correct 19 ms 49488 KB Output is correct
31 Correct 18 ms 49440 KB Output is correct
32 Correct 21 ms 49416 KB Output is correct
33 Correct 19 ms 49516 KB Output is correct
34 Correct 22 ms 49272 KB Output is correct
35 Correct 23 ms 49368 KB Output is correct
36 Correct 24 ms 49392 KB Output is correct
37 Correct 19 ms 49364 KB Output is correct
38 Correct 21 ms 49400 KB Output is correct
39 Correct 19 ms 49484 KB Output is correct
40 Correct 18 ms 49772 KB Output is correct
41 Correct 20 ms 50268 KB Output is correct
42 Correct 22 ms 50440 KB Output is correct
43 Correct 26 ms 50432 KB Output is correct
44 Correct 22 ms 50388 KB Output is correct
45 Correct 28 ms 50668 KB Output is correct
46 Correct 29 ms 50396 KB Output is correct
47 Correct 21 ms 50340 KB Output is correct
48 Correct 21 ms 50388 KB Output is correct
49 Correct 21 ms 50356 KB Output is correct
50 Correct 22 ms 50364 KB Output is correct
51 Correct 24 ms 50304 KB Output is correct
52 Correct 22 ms 50328 KB Output is correct
53 Correct 23 ms 50444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 49364 KB Output is correct
2 Correct 21 ms 49284 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 19 ms 49356 KB Output is correct
5 Correct 23 ms 49304 KB Output is correct
6 Correct 19 ms 49364 KB Output is correct
7 Correct 18 ms 49408 KB Output is correct
8 Correct 18 ms 49420 KB Output is correct
9 Correct 18 ms 49364 KB Output is correct
10 Correct 20 ms 49404 KB Output is correct
11 Correct 18 ms 49364 KB Output is correct
12 Correct 18 ms 49384 KB Output is correct
13 Correct 19 ms 49364 KB Output is correct
14 Correct 19 ms 49364 KB Output is correct
15 Correct 22 ms 49492 KB Output is correct
16 Correct 21 ms 49492 KB Output is correct
17 Correct 19 ms 49416 KB Output is correct
18 Correct 20 ms 49320 KB Output is correct
19 Correct 19 ms 49380 KB Output is correct
20 Correct 20 ms 49348 KB Output is correct
21 Correct 22 ms 49492 KB Output is correct
22 Correct 24 ms 49492 KB Output is correct
23 Correct 23 ms 49468 KB Output is correct
24 Correct 22 ms 49492 KB Output is correct
25 Correct 19 ms 49460 KB Output is correct
26 Correct 19 ms 49492 KB Output is correct
27 Correct 19 ms 49492 KB Output is correct
28 Correct 19 ms 49492 KB Output is correct
29 Correct 20 ms 49524 KB Output is correct
30 Correct 19 ms 49488 KB Output is correct
31 Correct 18 ms 49440 KB Output is correct
32 Correct 21 ms 49416 KB Output is correct
33 Correct 19 ms 49516 KB Output is correct
34 Correct 22 ms 49272 KB Output is correct
35 Correct 23 ms 49368 KB Output is correct
36 Correct 24 ms 49392 KB Output is correct
37 Correct 19 ms 49364 KB Output is correct
38 Correct 21 ms 49400 KB Output is correct
39 Correct 19 ms 49484 KB Output is correct
40 Correct 18 ms 49772 KB Output is correct
41 Correct 20 ms 50268 KB Output is correct
42 Correct 22 ms 50440 KB Output is correct
43 Correct 26 ms 50432 KB Output is correct
44 Correct 22 ms 50388 KB Output is correct
45 Correct 28 ms 50668 KB Output is correct
46 Correct 29 ms 50396 KB Output is correct
47 Correct 21 ms 50340 KB Output is correct
48 Correct 21 ms 50388 KB Output is correct
49 Correct 21 ms 50356 KB Output is correct
50 Correct 22 ms 50364 KB Output is correct
51 Correct 24 ms 50304 KB Output is correct
52 Correct 22 ms 50328 KB Output is correct
53 Correct 23 ms 50444 KB Output is correct
54 Correct 45 ms 52268 KB Output is correct
55 Correct 99 ms 57336 KB Output is correct
56 Correct 166 ms 57928 KB Output is correct
57 Correct 153 ms 57916 KB Output is correct
58 Correct 158 ms 57932 KB Output is correct
59 Correct 162 ms 57920 KB Output is correct
60 Correct 162 ms 57924 KB Output is correct
61 Correct 108 ms 57400 KB Output is correct
62 Correct 88 ms 57200 KB Output is correct
63 Correct 142 ms 57604 KB Output is correct
64 Correct 153 ms 57452 KB Output is correct
65 Correct 132 ms 57464 KB Output is correct
66 Correct 124 ms 57512 KB Output is correct
67 Correct 155 ms 57928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 49364 KB Output is correct
2 Correct 21 ms 49284 KB Output is correct
3 Correct 19 ms 49364 KB Output is correct
4 Correct 19 ms 49356 KB Output is correct
5 Correct 23 ms 49304 KB Output is correct
6 Correct 19 ms 49364 KB Output is correct
7 Correct 18 ms 49408 KB Output is correct
8 Correct 18 ms 49420 KB Output is correct
9 Correct 18 ms 49364 KB Output is correct
10 Correct 20 ms 49404 KB Output is correct
11 Correct 23 ms 49436 KB Output is correct
12 Correct 22 ms 49340 KB Output is correct
13 Correct 314 ms 69768 KB Output is correct
14 Correct 392 ms 72684 KB Output is correct
15 Correct 454 ms 75836 KB Output is correct
16 Correct 544 ms 79268 KB Output is correct
17 Correct 666 ms 82812 KB Output is correct
18 Correct 699 ms 82840 KB Output is correct
19 Correct 661 ms 82916 KB Output is correct
20 Correct 19 ms 49376 KB Output is correct
21 Correct 19 ms 49392 KB Output is correct
22 Correct 18 ms 49416 KB Output is correct
23 Correct 22 ms 49328 KB Output is correct
24 Correct 19 ms 49364 KB Output is correct
25 Correct 20 ms 49404 KB Output is correct
26 Correct 19 ms 49484 KB Output is correct
27 Correct 18 ms 49376 KB Output is correct
28 Correct 18 ms 49364 KB Output is correct
29 Correct 18 ms 49384 KB Output is correct
30 Correct 19 ms 49364 KB Output is correct
31 Correct 19 ms 49364 KB Output is correct
32 Correct 22 ms 49492 KB Output is correct
33 Correct 21 ms 49492 KB Output is correct
34 Correct 19 ms 49416 KB Output is correct
35 Correct 20 ms 49320 KB Output is correct
36 Correct 19 ms 49380 KB Output is correct
37 Correct 20 ms 49348 KB Output is correct
38 Correct 22 ms 49492 KB Output is correct
39 Correct 24 ms 49492 KB Output is correct
40 Correct 23 ms 49468 KB Output is correct
41 Correct 22 ms 49492 KB Output is correct
42 Correct 19 ms 49460 KB Output is correct
43 Correct 19 ms 49492 KB Output is correct
44 Correct 19 ms 49492 KB Output is correct
45 Correct 19 ms 49492 KB Output is correct
46 Correct 20 ms 49524 KB Output is correct
47 Correct 19 ms 49488 KB Output is correct
48 Correct 18 ms 49440 KB Output is correct
49 Correct 21 ms 49416 KB Output is correct
50 Correct 19 ms 49516 KB Output is correct
51 Correct 22 ms 49272 KB Output is correct
52 Correct 23 ms 49368 KB Output is correct
53 Correct 24 ms 49392 KB Output is correct
54 Correct 19 ms 49364 KB Output is correct
55 Correct 21 ms 49400 KB Output is correct
56 Correct 19 ms 49484 KB Output is correct
57 Correct 18 ms 49772 KB Output is correct
58 Correct 20 ms 50268 KB Output is correct
59 Correct 22 ms 50440 KB Output is correct
60 Correct 26 ms 50432 KB Output is correct
61 Correct 22 ms 50388 KB Output is correct
62 Correct 28 ms 50668 KB Output is correct
63 Correct 29 ms 50396 KB Output is correct
64 Correct 21 ms 50340 KB Output is correct
65 Correct 21 ms 50388 KB Output is correct
66 Correct 21 ms 50356 KB Output is correct
67 Correct 22 ms 50364 KB Output is correct
68 Correct 24 ms 50304 KB Output is correct
69 Correct 22 ms 50328 KB Output is correct
70 Correct 23 ms 50444 KB Output is correct
71 Correct 45 ms 52268 KB Output is correct
72 Correct 99 ms 57336 KB Output is correct
73 Correct 166 ms 57928 KB Output is correct
74 Correct 153 ms 57916 KB Output is correct
75 Correct 158 ms 57932 KB Output is correct
76 Correct 162 ms 57920 KB Output is correct
77 Correct 162 ms 57924 KB Output is correct
78 Correct 108 ms 57400 KB Output is correct
79 Correct 88 ms 57200 KB Output is correct
80 Correct 142 ms 57604 KB Output is correct
81 Correct 153 ms 57452 KB Output is correct
82 Correct 132 ms 57464 KB Output is correct
83 Correct 124 ms 57512 KB Output is correct
84 Correct 155 ms 57928 KB Output is correct
85 Correct 429 ms 66648 KB Output is correct
86 Correct 1077 ms 84580 KB Output is correct
87 Correct 988 ms 84712 KB Output is correct
88 Correct 1031 ms 84604 KB Output is correct
89 Correct 959 ms 84508 KB Output is correct
90 Correct 965 ms 84680 KB Output is correct
91 Correct 525 ms 82856 KB Output is correct
92 Correct 744 ms 82820 KB Output is correct
93 Correct 895 ms 83340 KB Output is correct
94 Correct 896 ms 83192 KB Output is correct
95 Correct 945 ms 83024 KB Output is correct
96 Correct 1026 ms 83036 KB Output is correct
97 Incorrect 1155 ms 84516 KB Output isn't correct
98 Halted 0 ms 0 KB -