Submission #719655

# Submission time Handle Problem Language Result Execution time Memory
719655 2023-04-06T12:58:10 Z Abrar_Al_Samit Copy and Paste 3 (JOI22_copypaste3) C++17
25 / 100
3000 ms 8276 KB
#include<bits/stdc++.h>
using namespace std;

const int nax = 1002;
const long long INF = 1e18;
const int P = 31;
const int M = 1e9 + 9;

int n;
string s;
long long A, B, C;
long long dp[nax][nax];
long long hv[nax];
long long pw[nax];

bool same(int l1, int r1, int l2, int r2) {
	long long h1 = hv[r1] - hv[l1-1];
	long long h2 = hv[r2] - hv[l2-1];
	if(h1<0) h1 += M;
	if(h2<0) h2 += M;

	if(r1<r2) h1 = (h1 * pw[r2-r1]) % M;
	else h2 = (h2 * pw[r1-r2]) % M;

	return h1==h2;
}
long long solve(int i, int j) {
	long long &ret = dp[i][j];
	if(ret!=-1) return ret;
	if(i==j) return A;

	ret = min((j-i+1) * A, solve(i+1, j) + A);

	for(int k=1; k<j-i+1; ++k) {
		int cnt = 0;
		int p = i;
		while(p+k-1<=j) {
			if(same(i, i+k-1, p, p+k-1)) {
				++cnt;
				p += k;
			} else ++p;
		}


		long long cur = solve(i, i+k-1) + B;
		cur += cnt * C;
		cur += ((j-i+1) - cnt * k) * A;

		ret = min(ret, cur);

	}
	return ret;
}
void PlayGround() {
	cin>>n>>s>>A>>B>>C;

	memset(dp, -1, sizeof dp);
	s = '@' + s;

	pw[0] = 1;
	for(int i=1; i<=n; ++i) {
		pw[i] = (pw[i-1] * P) % M;
		hv[i] = (pw[i] * (s[i]-'a'+1)) + hv[i-1];
		hv[i] %= M;
	}

	cout<<solve(1, n)<<'\n';

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	PlayGround();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Execution timed out 3036 ms 8276 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 3 ms 8148 KB Output is correct
12 Correct 3 ms 8148 KB Output is correct
13 Correct 3 ms 8148 KB Output is correct
14 Correct 5 ms 8148 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct
16 Correct 3 ms 8168 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 4 ms 8160 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 3 ms 8148 KB Output is correct
21 Correct 5 ms 8208 KB Output is correct
22 Correct 3 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 4 ms 8148 KB Output is correct
25 Correct 4 ms 8148 KB Output is correct
26 Correct 5 ms 8148 KB Output is correct
27 Correct 4 ms 8148 KB Output is correct
28 Correct 4 ms 8180 KB Output is correct
29 Correct 4 ms 8148 KB Output is correct
30 Correct 3 ms 8148 KB Output is correct
31 Correct 4 ms 8148 KB Output is correct
32 Correct 3 ms 8148 KB Output is correct
33 Correct 4 ms 8148 KB Output is correct
34 Correct 5 ms 8148 KB Output is correct
35 Correct 3 ms 8148 KB Output is correct
36 Correct 4 ms 8172 KB Output is correct
37 Correct 5 ms 8148 KB Output is correct
38 Correct 5 ms 8148 KB Output is correct
39 Correct 4 ms 8152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 3 ms 8148 KB Output is correct
12 Correct 3 ms 8148 KB Output is correct
13 Correct 3 ms 8148 KB Output is correct
14 Correct 5 ms 8148 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct
16 Correct 3 ms 8168 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 4 ms 8160 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 3 ms 8148 KB Output is correct
21 Correct 5 ms 8208 KB Output is correct
22 Correct 3 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 4 ms 8148 KB Output is correct
25 Correct 4 ms 8148 KB Output is correct
26 Correct 5 ms 8148 KB Output is correct
27 Correct 4 ms 8148 KB Output is correct
28 Correct 4 ms 8180 KB Output is correct
29 Correct 4 ms 8148 KB Output is correct
30 Correct 3 ms 8148 KB Output is correct
31 Correct 4 ms 8148 KB Output is correct
32 Correct 3 ms 8148 KB Output is correct
33 Correct 4 ms 8148 KB Output is correct
34 Correct 5 ms 8148 KB Output is correct
35 Correct 3 ms 8148 KB Output is correct
36 Correct 4 ms 8172 KB Output is correct
37 Correct 5 ms 8148 KB Output is correct
38 Correct 5 ms 8148 KB Output is correct
39 Correct 4 ms 8152 KB Output is correct
40 Correct 11 ms 8148 KB Output is correct
41 Correct 34 ms 8148 KB Output is correct
42 Correct 116 ms 8184 KB Output is correct
43 Correct 131 ms 8180 KB Output is correct
44 Correct 135 ms 8148 KB Output is correct
45 Correct 118 ms 8148 KB Output is correct
46 Correct 116 ms 8148 KB Output is correct
47 Correct 82 ms 8180 KB Output is correct
48 Correct 109 ms 8148 KB Output is correct
49 Correct 110 ms 8176 KB Output is correct
50 Correct 104 ms 8192 KB Output is correct
51 Correct 89 ms 8176 KB Output is correct
52 Correct 114 ms 8180 KB Output is correct
53 Correct 121 ms 8180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 3 ms 8148 KB Output is correct
12 Correct 3 ms 8148 KB Output is correct
13 Correct 3 ms 8148 KB Output is correct
14 Correct 5 ms 8148 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct
16 Correct 3 ms 8168 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 4 ms 8160 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 3 ms 8148 KB Output is correct
21 Correct 5 ms 8208 KB Output is correct
22 Correct 3 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 4 ms 8148 KB Output is correct
25 Correct 4 ms 8148 KB Output is correct
26 Correct 5 ms 8148 KB Output is correct
27 Correct 4 ms 8148 KB Output is correct
28 Correct 4 ms 8180 KB Output is correct
29 Correct 4 ms 8148 KB Output is correct
30 Correct 3 ms 8148 KB Output is correct
31 Correct 4 ms 8148 KB Output is correct
32 Correct 3 ms 8148 KB Output is correct
33 Correct 4 ms 8148 KB Output is correct
34 Correct 5 ms 8148 KB Output is correct
35 Correct 3 ms 8148 KB Output is correct
36 Correct 4 ms 8172 KB Output is correct
37 Correct 5 ms 8148 KB Output is correct
38 Correct 5 ms 8148 KB Output is correct
39 Correct 4 ms 8152 KB Output is correct
40 Correct 11 ms 8148 KB Output is correct
41 Correct 34 ms 8148 KB Output is correct
42 Correct 116 ms 8184 KB Output is correct
43 Correct 131 ms 8180 KB Output is correct
44 Correct 135 ms 8148 KB Output is correct
45 Correct 118 ms 8148 KB Output is correct
46 Correct 116 ms 8148 KB Output is correct
47 Correct 82 ms 8180 KB Output is correct
48 Correct 109 ms 8148 KB Output is correct
49 Correct 110 ms 8176 KB Output is correct
50 Correct 104 ms 8192 KB Output is correct
51 Correct 89 ms 8176 KB Output is correct
52 Correct 114 ms 8180 KB Output is correct
53 Correct 121 ms 8180 KB Output is correct
54 Correct 2524 ms 8216 KB Output is correct
55 Execution timed out 3083 ms 8276 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 4 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 4 ms 8148 KB Output is correct
13 Execution timed out 3036 ms 8276 KB Time limit exceeded
14 Halted 0 ms 0 KB -