Submission #587747

# Submission time Handle Problem Language Result Execution time Memory
587747 2022-07-02T10:08:39 Z Tekor Copy and Paste 3 (JOI22_copypaste3) C++17
25 / 100
3000 ms 8612 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair <ll,ll>
#define mp make_pair
#define f first
#define s second
#define all(v) v.begin(),v.end()
void boos() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
const int N = 1e3 + 1;
const ll p = 433,p1 = 383;
const ll INF = (ll)1e9 + 7ll;
ll binpow(ll a,ll b) {
	ll ans = 1,k = a;
	while(b) { 
		if(b % 2)ans *= k;
		ans %= INF;
		k *= k;
		k %= INF;
		b /= 2ll;
	}
	return ans;
}
ll has[N],has1[N],st[N],st1[N];
ll dp[N][N];
ll cc[N];
pll calc(int l,int r) {
	ll tek = (has[r] - has[l - 1] + INF) % INF;
	tek = (tek * st[l]) % INF;
	ll tek1 = (has1[r] - has1[l - 1] + INF) % INF;
	tek1 = (tek1 * st1[l]) % INF;
	return mp(tek,tek1);
}
void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll a,b,c;
	cin >> a >> b >> c;
	s = "0" + s;
	ll tek = p,tek1 = p1;
	st[1] = binpow(tek,INF - 2);
	st1[1] = binpow(tek1,INF - 2);
	has[1] = (s[1] - 'a' + 1ll);
	has1[1] = has[1];
	for(int i = 2;i <= n;i++) {
		ll val = (s[i] - 'a' + 1ll);
		has[i] = (has[i - 1] + (tek * val) % INF) % INF;
		has1[i] = (has1[i - 1] + (tek1 * val) % INF) % INF;
		tek = (tek * p) % INF;
		tek1 = (tek1 * p1) % INF;
		st[i] = binpow(tek,INF - 2);
		st1[i] = binpow(tek1,INF - 2);
	}
	for(int i = 1;i <= n;i++)dp[i][i] = a;
	for(int sz = 2;sz <= n;sz++) {
		for(int l = 1;l <= n - sz + 1;l++) {
			int r = l + sz - 1;
			dp[l][r] = dp[l][r - 1] + a;
			for(int sz1 = 1;sz1 * 2 <= sz;sz1++) {
				for(int h = l;h <= r;h++)cc[h] = 1;
				for(int h = r - 2 * sz1 + 1;h >= l;h--) {
					cc[h] = max(cc[h],cc[h + 1]);
					if(calc(h,h + sz1 - 1) == calc(r - sz1 + 1,r)) {
						//cout << h << " " << h + sz1 - 1 << " === " << r - sz1 + 1 << " " << r << endl;
						cc[h] = max(cc[h],cc[h + sz1] + 1);
					}
					dp[l][r] = min(dp[l][r],cc[h] * c + b + a * (ll)(sz - cc[h] * sz1) + dp[r - sz1 + 1][r]);
				}
			}
		}
	}
	cout << dp[1][n];
}
int main() {
	boos();
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Runtime error 11 ms 8612 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 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 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 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 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 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 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 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 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 32 ms 708 KB Output is correct
41 Correct 702 ms 1364 KB Output is correct
42 Correct 639 ms 1364 KB Output is correct
43 Correct 666 ms 1276 KB Output is correct
44 Correct 658 ms 1272 KB Output is correct
45 Correct 618 ms 1276 KB Output is correct
46 Correct 619 ms 1188 KB Output is correct
47 Correct 710 ms 1236 KB Output is correct
48 Correct 638 ms 1348 KB Output is correct
49 Correct 635 ms 1452 KB Output is correct
50 Correct 641 ms 1228 KB Output is correct
51 Correct 696 ms 1380 KB Output is correct
52 Correct 652 ms 1332 KB Output is correct
53 Correct 639 ms 1384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 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 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 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 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 32 ms 708 KB Output is correct
41 Correct 702 ms 1364 KB Output is correct
42 Correct 639 ms 1364 KB Output is correct
43 Correct 666 ms 1276 KB Output is correct
44 Correct 658 ms 1272 KB Output is correct
45 Correct 618 ms 1276 KB Output is correct
46 Correct 619 ms 1188 KB Output is correct
47 Correct 710 ms 1236 KB Output is correct
48 Correct 638 ms 1348 KB Output is correct
49 Correct 635 ms 1452 KB Output is correct
50 Correct 641 ms 1228 KB Output is correct
51 Correct 696 ms 1380 KB Output is correct
52 Correct 652 ms 1332 KB Output is correct
53 Correct 639 ms 1384 KB Output is correct
54 Execution timed out 3065 ms 2836 KB Time limit exceeded
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 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 Runtime error 11 ms 8612 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -