#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
ll n;
char s[2510];
ll A, B, C;
ll dp[2510][2510];
ll je[2510];
ll num[2510][2510];
ll nu[2510];
ll hs = 31;
ll ss = 1000000007;
ll L[6300010], R[6300010];
ll GO[6300010];
map<ll, vector<ll> > mp;
ll cc;
ll minn[2510];
ll gaet[2510];
vector<ll> vv[2510];
ll sqrmtp(ll X, ll Y)
{
ll ret = 1;
while(Y)
{
if(Y & 1)
ret = ret * X % ss;
X = X * X % ss;
Y >>= 1;
}
return ret;
}
ll f(ll L, ll R)
{
ll ret = (nu[R] - nu[L - 1]) % ss * sqrmtp(je[L], ss - 2) % ss;
return (ret % ss + ss) % ss;
}
ll comp(ll L1, ll R1, ll L2, ll R2)
{
return f(L1, R1) == f(L2, R2);
}
int main(void)
{
fastio
cin >> n;
for(ll i = 1 ; i <= n ; i++)
cin >> s[i];
cin >> A;
cin >> B;
cin >> C;
je[0] = 1;
for(ll i = 1 ; i <= n ; i++)
je[i] = je[i - 1] * hs % ss;
for(ll i = 1 ; i <= n ; i++)
nu[i] = (nu[i - 1] + je[i] * (s[i] - 'a' + 1) % ss) % ss;
for(ll i = 1 ; i <= n ; i++)
{
for(ll j = i ; j <= n ; j++)
{
num[i][j] = ++cc;
mp[f(i, j)].push_back(cc);
L[cc] = i, R[cc] = j;
}
}
for(auto &i : mp)
{
vector<ll> tmp = i.se;
ll siz = (ll)tmp.size();
for(ll j = 1 ; j < siz ; j++)
{
ll l = 0, r = j - 1;
while(l <= r)
{
ll mid = (l + r) >> 1;
if(R[tmp[mid]] < L[tmp[j]])
l = mid + 1;
else
r = mid - 1;
}
if(r == -1)
continue;
GO[tmp[j]] = tmp[r];
}
}
for(ll i = 1 ; i <= n ; i++)
{
for(ll j = 1 ; j <= n + 1 ; j++)
{
minn[j] = INF;
vv[j].clear();
gaet[j] = 0;
}
ll minn = INF;
for(ll j = i ; j >= 1 ; j--)
{
ll X = num[j][i];
while(X)
{
vv[L[X]].push_back(j);
X = GO[X];
}
}
for(ll j = i ; j >= 1 ; j--)
{
dp[j][i] = (i - j + 1) * A;
dp[j][i] = min(dp[j][i], dp[j][i - 1] + A);
for(auto &k : vv[j])
{
gaet[k]++;
minn = min(minn, B + dp[k][i] + gaet[k] * (C - A * (i - k + 1)));
}
dp[j][i] = min(dp[j][i], minn + A * (i - j + 1));
}
}
cout << dp[1][n];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1065 ms |
122128 KB |
Output is correct |
4 |
Correct |
1274 ms |
137232 KB |
Output is correct |
5 |
Correct |
1453 ms |
152672 KB |
Output is correct |
6 |
Correct |
1728 ms |
177188 KB |
Output is correct |
7 |
Correct |
2035 ms |
193448 KB |
Output is correct |
8 |
Correct |
2039 ms |
193640 KB |
Output is correct |
9 |
Correct |
2060 ms |
193544 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6748 KB |
Output is correct |
16 |
Correct |
1 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6744 KB |
Output is correct |
12 |
Correct |
1 ms |
6744 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6744 KB |
Output is correct |
16 |
Correct |
1 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6744 KB |
Output is correct |
20 |
Correct |
1 ms |
6488 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6744 KB |
Output is correct |
24 |
Correct |
1 ms |
6744 KB |
Output is correct |
25 |
Correct |
1 ms |
6744 KB |
Output is correct |
26 |
Correct |
2 ms |
6744 KB |
Output is correct |
27 |
Correct |
1 ms |
6744 KB |
Output is correct |
28 |
Correct |
1 ms |
6744 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
2 ms |
6744 KB |
Output is correct |
31 |
Correct |
1 ms |
6744 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
1 ms |
6488 KB |
Output is correct |
35 |
Correct |
1 ms |
6488 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6744 KB |
Output is correct |
39 |
Correct |
1 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6744 KB |
Output is correct |
12 |
Correct |
1 ms |
6744 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6744 KB |
Output is correct |
16 |
Correct |
1 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6744 KB |
Output is correct |
20 |
Correct |
1 ms |
6488 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6744 KB |
Output is correct |
24 |
Correct |
1 ms |
6744 KB |
Output is correct |
25 |
Correct |
1 ms |
6744 KB |
Output is correct |
26 |
Correct |
2 ms |
6744 KB |
Output is correct |
27 |
Correct |
1 ms |
6744 KB |
Output is correct |
28 |
Correct |
1 ms |
6744 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
2 ms |
6744 KB |
Output is correct |
31 |
Correct |
1 ms |
6744 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
1 ms |
6488 KB |
Output is correct |
35 |
Correct |
1 ms |
6488 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6744 KB |
Output is correct |
39 |
Correct |
1 ms |
6744 KB |
Output is correct |
40 |
Correct |
4 ms |
9304 KB |
Output is correct |
41 |
Correct |
12 ms |
14168 KB |
Output is correct |
42 |
Correct |
16 ms |
15964 KB |
Output is correct |
43 |
Correct |
16 ms |
15960 KB |
Output is correct |
44 |
Correct |
16 ms |
15964 KB |
Output is correct |
45 |
Correct |
17 ms |
15960 KB |
Output is correct |
46 |
Correct |
16 ms |
15960 KB |
Output is correct |
47 |
Correct |
13 ms |
14424 KB |
Output is correct |
48 |
Correct |
15 ms |
15192 KB |
Output is correct |
49 |
Correct |
16 ms |
15324 KB |
Output is correct |
50 |
Correct |
15 ms |
15452 KB |
Output is correct |
51 |
Correct |
15 ms |
15192 KB |
Output is correct |
52 |
Correct |
15 ms |
15192 KB |
Output is correct |
53 |
Correct |
16 ms |
15960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6744 KB |
Output is correct |
12 |
Correct |
1 ms |
6744 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6744 KB |
Output is correct |
16 |
Correct |
1 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6744 KB |
Output is correct |
20 |
Correct |
1 ms |
6488 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6744 KB |
Output is correct |
24 |
Correct |
1 ms |
6744 KB |
Output is correct |
25 |
Correct |
1 ms |
6744 KB |
Output is correct |
26 |
Correct |
2 ms |
6744 KB |
Output is correct |
27 |
Correct |
1 ms |
6744 KB |
Output is correct |
28 |
Correct |
1 ms |
6744 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
2 ms |
6744 KB |
Output is correct |
31 |
Correct |
1 ms |
6744 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
1 ms |
6488 KB |
Output is correct |
35 |
Correct |
1 ms |
6488 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6744 KB |
Output is correct |
39 |
Correct |
1 ms |
6744 KB |
Output is correct |
40 |
Correct |
4 ms |
9304 KB |
Output is correct |
41 |
Correct |
12 ms |
14168 KB |
Output is correct |
42 |
Correct |
16 ms |
15964 KB |
Output is correct |
43 |
Correct |
16 ms |
15960 KB |
Output is correct |
44 |
Correct |
16 ms |
15964 KB |
Output is correct |
45 |
Correct |
17 ms |
15960 KB |
Output is correct |
46 |
Correct |
16 ms |
15960 KB |
Output is correct |
47 |
Correct |
13 ms |
14424 KB |
Output is correct |
48 |
Correct |
15 ms |
15192 KB |
Output is correct |
49 |
Correct |
16 ms |
15324 KB |
Output is correct |
50 |
Correct |
15 ms |
15452 KB |
Output is correct |
51 |
Correct |
15 ms |
15192 KB |
Output is correct |
52 |
Correct |
15 ms |
15192 KB |
Output is correct |
53 |
Correct |
16 ms |
15960 KB |
Output is correct |
54 |
Correct |
91 ms |
32284 KB |
Output is correct |
55 |
Correct |
285 ms |
48936 KB |
Output is correct |
56 |
Incorrect |
695 ms |
97692 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6744 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1065 ms |
122128 KB |
Output is correct |
14 |
Correct |
1274 ms |
137232 KB |
Output is correct |
15 |
Correct |
1453 ms |
152672 KB |
Output is correct |
16 |
Correct |
1728 ms |
177188 KB |
Output is correct |
17 |
Correct |
2035 ms |
193448 KB |
Output is correct |
18 |
Correct |
2039 ms |
193640 KB |
Output is correct |
19 |
Correct |
2060 ms |
193544 KB |
Output is correct |
20 |
Correct |
1 ms |
6488 KB |
Output is correct |
21 |
Correct |
1 ms |
6488 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 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 |
6748 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6744 KB |
Output is correct |
29 |
Correct |
1 ms |
6744 KB |
Output is correct |
30 |
Correct |
1 ms |
6744 KB |
Output is correct |
31 |
Correct |
1 ms |
6488 KB |
Output is correct |
32 |
Correct |
1 ms |
6744 KB |
Output is correct |
33 |
Correct |
1 ms |
6748 KB |
Output is correct |
34 |
Correct |
1 ms |
6488 KB |
Output is correct |
35 |
Correct |
1 ms |
6488 KB |
Output is correct |
36 |
Correct |
1 ms |
6744 KB |
Output is correct |
37 |
Correct |
1 ms |
6488 KB |
Output is correct |
38 |
Correct |
2 ms |
6748 KB |
Output is correct |
39 |
Correct |
2 ms |
6744 KB |
Output is correct |
40 |
Correct |
2 ms |
6744 KB |
Output is correct |
41 |
Correct |
1 ms |
6744 KB |
Output is correct |
42 |
Correct |
1 ms |
6744 KB |
Output is correct |
43 |
Correct |
2 ms |
6744 KB |
Output is correct |
44 |
Correct |
1 ms |
6744 KB |
Output is correct |
45 |
Correct |
1 ms |
6744 KB |
Output is correct |
46 |
Correct |
2 ms |
6744 KB |
Output is correct |
47 |
Correct |
2 ms |
6744 KB |
Output is correct |
48 |
Correct |
1 ms |
6744 KB |
Output is correct |
49 |
Correct |
2 ms |
6748 KB |
Output is correct |
50 |
Correct |
2 ms |
6748 KB |
Output is correct |
51 |
Correct |
1 ms |
6488 KB |
Output is correct |
52 |
Correct |
1 ms |
6488 KB |
Output is correct |
53 |
Correct |
1 ms |
6492 KB |
Output is correct |
54 |
Correct |
1 ms |
6492 KB |
Output is correct |
55 |
Correct |
1 ms |
6744 KB |
Output is correct |
56 |
Correct |
1 ms |
6744 KB |
Output is correct |
57 |
Correct |
4 ms |
9304 KB |
Output is correct |
58 |
Correct |
12 ms |
14168 KB |
Output is correct |
59 |
Correct |
16 ms |
15964 KB |
Output is correct |
60 |
Correct |
16 ms |
15960 KB |
Output is correct |
61 |
Correct |
16 ms |
15964 KB |
Output is correct |
62 |
Correct |
17 ms |
15960 KB |
Output is correct |
63 |
Correct |
16 ms |
15960 KB |
Output is correct |
64 |
Correct |
13 ms |
14424 KB |
Output is correct |
65 |
Correct |
15 ms |
15192 KB |
Output is correct |
66 |
Correct |
16 ms |
15324 KB |
Output is correct |
67 |
Correct |
15 ms |
15452 KB |
Output is correct |
68 |
Correct |
15 ms |
15192 KB |
Output is correct |
69 |
Correct |
15 ms |
15192 KB |
Output is correct |
70 |
Correct |
16 ms |
15960 KB |
Output is correct |
71 |
Correct |
91 ms |
32284 KB |
Output is correct |
72 |
Correct |
285 ms |
48936 KB |
Output is correct |
73 |
Incorrect |
695 ms |
97692 KB |
Output isn't correct |
74 |
Halted |
0 ms |
0 KB |
- |