Submission #634462

# Submission time Handle Problem Language Result Execution time Memory
634462 2022-08-24T12:58:01 Z LittleCube Copy and Paste 3 (JOI22_copypaste3) C++14
57 / 100
3000 ms 14156 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

const ll base = 29, mod = 1234567891;

int N;
char c[1005];
ll A, B, C, dp[1005][1005], h[1005][1005];

signed main()
{
	cin >> N;
	for(int i = 1; i <= N; i++)
		cin >> c[i];
	cin >> A >> B >> C;
	for(int i = 1; i <= N; i++)
		for(int j = i; j <= N; j++)
		{
			dp[i][j] = A * (j - i + 1);
			h[i][j] = (h[i][j - 1] * base + c[j] - 'a') % mod;
		}
	for(int i = N; i >= 1; i--)
		for(int k = i; k <= N; k++)
		{	
			for(int j = i + 1; j <= k; j++)
				dp[i][k] = min(dp[i][k], dp[j][k] + (j - i) * A);
			ll cur = dp[i][k] + B + C, pre = k;
			// cout << "copy: " << i << ' ' << k << " initial " << cur << '\n';
			for(int j = k + 1; j <= N; j++)
			{
				cur += A;
				if(pre < j - k + i && h[j - k + i][j] == h[i][k])
				{	
					cur += -(k - i + 1) * A + C;
					pre = j;
				}
				// cout << "copy: " << i << ' ' << k << " to " << i << ' ' << j << " cost " << cur << '\n';
				dp[i][j] = min(dp[i][j], cur);
			}
		}
	/* for(int i = 1; i <= N; i++)
		for(int j = 1; j <= N; j++)
			if(j < i) cout << "- ";
			else cout << dp[i][j] << " \n"[N == j];
	*/
	cout << dp[1][N] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 Execution timed out 3074 ms 212 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 1 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 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 212 KB Output is correct
35 Correct 1 ms 212 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 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 1 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 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 212 KB Output is correct
35 Correct 1 ms 212 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 1 ms 468 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 5 ms 2132 KB Output is correct
42 Correct 5 ms 2132 KB Output is correct
43 Correct 15 ms 2132 KB Output is correct
44 Correct 6 ms 2132 KB Output is correct
45 Correct 5 ms 2132 KB Output is correct
46 Correct 5 ms 2248 KB Output is correct
47 Correct 5 ms 2132 KB Output is correct
48 Correct 5 ms 2132 KB Output is correct
49 Correct 6 ms 2132 KB Output is correct
50 Correct 5 ms 2132 KB Output is correct
51 Correct 6 ms 2132 KB Output is correct
52 Correct 5 ms 2132 KB Output is correct
53 Correct 5 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 1 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 0 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 212 KB Output is correct
35 Correct 1 ms 212 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 1 ms 468 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 5 ms 2132 KB Output is correct
42 Correct 5 ms 2132 KB Output is correct
43 Correct 15 ms 2132 KB Output is correct
44 Correct 6 ms 2132 KB Output is correct
45 Correct 5 ms 2132 KB Output is correct
46 Correct 5 ms 2248 KB Output is correct
47 Correct 5 ms 2132 KB Output is correct
48 Correct 5 ms 2132 KB Output is correct
49 Correct 6 ms 2132 KB Output is correct
50 Correct 5 ms 2132 KB Output is correct
51 Correct 6 ms 2132 KB Output is correct
52 Correct 5 ms 2132 KB Output is correct
53 Correct 5 ms 2132 KB Output is correct
54 Correct 48 ms 5432 KB Output is correct
55 Correct 392 ms 14084 KB Output is correct
56 Correct 454 ms 14120 KB Output is correct
57 Correct 424 ms 14124 KB Output is correct
58 Correct 501 ms 14116 KB Output is correct
59 Correct 440 ms 14116 KB Output is correct
60 Correct 488 ms 14120 KB Output is correct
61 Correct 429 ms 14120 KB Output is correct
62 Correct 394 ms 14120 KB Output is correct
63 Correct 437 ms 14156 KB Output is correct
64 Correct 436 ms 14116 KB Output is correct
65 Correct 439 ms 14116 KB Output is correct
66 Correct 455 ms 14036 KB Output is correct
67 Correct 429 ms 14120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 Execution timed out 3074 ms 212 KB Time limit exceeded
14 Halted 0 ms 0 KB -