Submission #1115506

# Submission time Handle Problem Language Result Execution time Memory
1115506 2024-11-20T14:25:24 Z thelegendary08 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
771 ms 294508 KB
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vc vector<char>
#define vb vector<bool>
#define mii map<int,int>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define in(a) int a; cin>>a
#define in2(a,b) int a,b; cin>>a>>b
#define in3(a,b,c) int a,b,c; cin>>a>>b>>c
#define in4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d
#define vin(v,n); vi v(n); f0r(i,n){cin>>v[i];}
#define out(a) cout<<a<<'\n'
#define out2(a,b) cout<<a<<' '<<b<<'\n'
#define out3(a,b,c) cout<<a<<' '<<b<<' '<<c<<'\n'
#define out4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<'\n'
#define vout(v) cout<<#v<<' '; for(auto u : v){cout<<u<<' ';} cout<<'\n'
#define dout(a) cout<<a<<' '<<#a<<'\n'
#define dout2(a,b) cout<<a<<' '<<#a<<' '<<b<<' '<<#b<<'\n'
#define yn(x); if(x){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';}
const int leg = 1e9 + 7;
const int mod = 1e15 + 1911;
using namespace std;
const int A = 711;
int minu(int a, int b){
	int ret = (a - b) % mod;
	if(ret < 0)ret += mod;
	return ret;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//ifstream cin(".in");
	//ofstream cout(".out");
	in(n);
	string s;
	cin>>s;
	vi h(n);
	h[0] = s[0];
	FOR(i, 1, n)h[i] = (h[i-1] * A + s[i]) % mod;
	vi p(n);
	p[0] = 1;
	FOR(i, 1, n)p[i] = (p[i-1] * A) % mod;
	//vout(h);
	//vout(p);
	in3(a,b,c);
	
	vvi dp(n, vi(n));
	f0r(i,n){
		FOR(j, i, n){
			dp[i][j] = (j - i + 1) * a;
		}
	}
	vvi hash(n, vi(n));
	f0r(i,n){
		hash[i][i] = s[i];
		FOR(j, i+1, n){
			hash[i][j] = (hash[i][j-1] * A + s[j]) % mod;
		}
	}
	f0r(i,n){
		//vout(hash[i]);
	}
	vvi nxt(n+1, vi(n, -1));
	FOR(i, 1, n+1){
		mii prev;
		f0r(j,n-i+1){
			if(prev.count(hash[j][j + i - 1]) == 0){
				prev[hash[j][j + i - 1]] = j;
			}
			else{
				int p = prev[hash[j][j + i - 1]];
				if(p + i - 1 < j){
					nxt[i][p] = j;
					prev[hash[j][j + i - 1]] = j;
				}
				
			}
		}
	}
	FOR(i, 1, n+1){
		//vout(nxt[i]);
	}
	vector<vector<vpii>>t(n, vector<vpii>(n));
	FOR(sz, 1, n+1){
		f0r(i, n - sz + 1){
			if(sz != 1)dp[i][i + sz - 1] = min(dp[i][i+sz-1], min(dp[i][i+sz-2], dp[i+1][i+sz-1]) + a);
			//else dp[i][i] = a;
			int cur = i;
			int count = 1;
			while(cur != -1){
				cur = nxt[sz][cur];
				if(cur != -1){
					//out2(i, cur + sz - 1);
					//out4(i, i+sz-1, count, (count + 1) * c + (cur + sz - 1 - i + 1 - (count + 1) * sz) * a + b + dp[i][i + sz - 1]);
					dp[i][cur + sz - 1] = min(dp[i][cur + sz - 1], (count + 1) * c + (cur + sz - 1 - i + 1 - (count + 1) * sz) * a + b + dp[i][i + sz - 1]);
				}
				count++;
			}
		}
	}
	
	f0r(i,n){
		//vout(dp[i]);
	}
	out(dp[0][n-1]);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 150 ms 157660 KB Output is correct
4 Correct 170 ms 184220 KB Output is correct
5 Correct 202 ms 215420 KB Output is correct
6 Correct 247 ms 251464 KB Output is correct
7 Correct 288 ms 294492 KB Output is correct
8 Correct 290 ms 294472 KB Output is correct
9 Correct 297 ms 294452 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 524 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 524 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 504 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 524 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 524 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 504 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 592 KB Output is correct
41 Correct 2 ms 2128 KB Output is correct
42 Correct 5 ms 2128 KB Output is correct
43 Correct 4 ms 2384 KB Output is correct
44 Correct 5 ms 2384 KB Output is correct
45 Correct 5 ms 2128 KB Output is correct
46 Correct 4 ms 2384 KB Output is correct
47 Correct 4 ms 2128 KB Output is correct
48 Correct 5 ms 2128 KB Output is correct
49 Correct 5 ms 2128 KB Output is correct
50 Correct 5 ms 2296 KB Output is correct
51 Correct 4 ms 2128 KB Output is correct
52 Correct 4 ms 2128 KB Output is correct
53 Correct 4 ms 2204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 524 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 524 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 504 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 592 KB Output is correct
41 Correct 2 ms 2128 KB Output is correct
42 Correct 5 ms 2128 KB Output is correct
43 Correct 4 ms 2384 KB Output is correct
44 Correct 5 ms 2384 KB Output is correct
45 Correct 5 ms 2128 KB Output is correct
46 Correct 4 ms 2384 KB Output is correct
47 Correct 4 ms 2128 KB Output is correct
48 Correct 5 ms 2128 KB Output is correct
49 Correct 5 ms 2128 KB Output is correct
50 Correct 5 ms 2296 KB Output is correct
51 Correct 4 ms 2128 KB Output is correct
52 Correct 4 ms 2128 KB Output is correct
53 Correct 4 ms 2204 KB Output is correct
54 Correct 24 ms 9808 KB Output is correct
55 Correct 41 ms 47440 KB Output is correct
56 Correct 100 ms 47432 KB Output is correct
57 Correct 97 ms 47432 KB Output is correct
58 Correct 98 ms 47432 KB Output is correct
59 Correct 102 ms 47560 KB Output is correct
60 Correct 107 ms 47432 KB Output is correct
61 Correct 85 ms 47444 KB Output is correct
62 Correct 40 ms 47440 KB Output is correct
63 Correct 95 ms 47404 KB Output is correct
64 Correct 94 ms 47504 KB Output is correct
65 Correct 80 ms 47444 KB Output is correct
66 Correct 92 ms 47384 KB Output is correct
67 Correct 97 ms 47432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 504 KB Output is correct
13 Correct 150 ms 157660 KB Output is correct
14 Correct 170 ms 184220 KB Output is correct
15 Correct 202 ms 215420 KB Output is correct
16 Correct 247 ms 251464 KB Output is correct
17 Correct 288 ms 294492 KB Output is correct
18 Correct 290 ms 294472 KB Output is correct
19 Correct 297 ms 294452 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 524 KB Output is correct
38 Correct 2 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 524 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 504 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 1 ms 336 KB Output is correct
56 Correct 1 ms 336 KB Output is correct
57 Correct 1 ms 592 KB Output is correct
58 Correct 2 ms 2128 KB Output is correct
59 Correct 5 ms 2128 KB Output is correct
60 Correct 4 ms 2384 KB Output is correct
61 Correct 5 ms 2384 KB Output is correct
62 Correct 5 ms 2128 KB Output is correct
63 Correct 4 ms 2384 KB Output is correct
64 Correct 4 ms 2128 KB Output is correct
65 Correct 5 ms 2128 KB Output is correct
66 Correct 5 ms 2128 KB Output is correct
67 Correct 5 ms 2296 KB Output is correct
68 Correct 4 ms 2128 KB Output is correct
69 Correct 4 ms 2128 KB Output is correct
70 Correct 4 ms 2204 KB Output is correct
71 Correct 24 ms 9808 KB Output is correct
72 Correct 41 ms 47440 KB Output is correct
73 Correct 100 ms 47432 KB Output is correct
74 Correct 97 ms 47432 KB Output is correct
75 Correct 98 ms 47432 KB Output is correct
76 Correct 102 ms 47560 KB Output is correct
77 Correct 107 ms 47432 KB Output is correct
78 Correct 85 ms 47444 KB Output is correct
79 Correct 40 ms 47440 KB Output is correct
80 Correct 95 ms 47404 KB Output is correct
81 Correct 94 ms 47504 KB Output is correct
82 Correct 80 ms 47444 KB Output is correct
83 Correct 92 ms 47384 KB Output is correct
84 Correct 97 ms 47432 KB Output is correct
85 Correct 262 ms 118056 KB Output is correct
86 Correct 735 ms 294484 KB Output is correct
87 Correct 766 ms 294472 KB Output is correct
88 Correct 771 ms 294472 KB Output is correct
89 Correct 763 ms 294500 KB Output is correct
90 Correct 752 ms 294480 KB Output is correct
91 Correct 379 ms 294472 KB Output is correct
92 Correct 309 ms 294472 KB Output is correct
93 Correct 727 ms 294388 KB Output is correct
94 Correct 687 ms 294472 KB Output is correct
95 Correct 627 ms 294508 KB Output is correct
96 Correct 627 ms 294308 KB Output is correct
97 Correct 714 ms 294472 KB Output is correct