답안 #897215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897215 2024-01-02T17:47:42 Z PoPularPlusPlus Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
542 ms 122896 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define vf first 
#define vs second
const ll mod = 1000000000100011;

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const ll P = 59;

ll convert(char c){
	return (c-'a') + 1;
}

void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll a , b , c;
	cin >> a >> b >> c;
	ll dp[n][n];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			dp[i][j] = 1e18;
		}
	}

	ll hash_val[n][n];

	for(int l = 0; l < n; l++)
	{
		hash_val[l][l] = (s[l] - 'a' + 1);
		for(int r = l+1; r < n; r++)
		{
			hash_val[l][r] = (hash_val[l][r-1] * P  +  (s[r] - 'a' + 1)) % mod;
		}
	
	}

	int next[n][n];
	memset(next,-1,sizeof next);

	for(int len = 0; len < n; len++){
		vector<pair<int,int>> v;
		for(int i = 0; i + len < n; i++){
			v.pb(mp(hash_val[i][i+len],i));
		}
		sort(all(v));

		while(v.size()){

			int hash = v.back().vf;

			for(int i = v.size()-1; i >= 0 && v[i].vf == hash; i--){
				while(v.size() > i + 2 && v[v.size()-2].vs > v[i].vs + len)
					v.pop_back();

				if(v.back().vs > v[i].vs + len)
					next[v[i].vs][v[i].vs+len] = v.back().vs;
			}

			while(v.size() && v.back().vf == hash)
				v.pop_back();
		}
	}

	for(int len = 0; len < n; len++){
		for(int i = 0; i + len < n; i++){
			int j = i + len;
			dp[i][j] = min(dp[i][j],(len+1LL)*a);
			if(len > 0){
				dp[i][j] = min(dp[i][j] , min(dp[i+1][j] , dp[i][j-1]) + a);
			}
			ll val = dp[i][j] + b;
			val += c;
			int x = i , y = j;
			while(next[x][y] != -1){
				int pos = next[x][y];
				val += c;
				val += (pos - (y + 1LL))*a;
				dp[i][pos + len] = min(dp[i][pos+len],val);
				x = pos;
				y = pos + len;
			}
		}
	}

	cout << dp[0][n-1] << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//int t;cin>>t;
	//while(t--)
		solve();
	return 0;
}

Compilation message

copypaste3.cpp: In function 'void solve()':
copypaste3.cpp:60:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |     while(v.size() > i + 2 && v[v.size()-2].vs > v[i].vs + len)
      |           ~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 225 ms 65860 KB Output is correct
4 Correct 269 ms 76956 KB Output is correct
5 Correct 345 ms 89912 KB Output is correct
6 Correct 429 ms 105004 KB Output is correct
7 Correct 542 ms 122804 KB Output is correct
8 Correct 488 ms 122808 KB Output is correct
9 Correct 508 ms 122804 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 600 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 600 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 1116 KB Output is correct
42 Correct 2 ms 1116 KB Output is correct
43 Correct 2 ms 1116 KB Output is correct
44 Correct 2 ms 1116 KB Output is correct
45 Correct 2 ms 1116 KB Output is correct
46 Correct 2 ms 1116 KB Output is correct
47 Correct 2 ms 1116 KB Output is correct
48 Correct 2 ms 1116 KB Output is correct
49 Correct 2 ms 1116 KB Output is correct
50 Correct 2 ms 1116 KB Output is correct
51 Correct 2 ms 1116 KB Output is correct
52 Correct 2 ms 1116 KB Output is correct
53 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 600 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 1116 KB Output is correct
42 Correct 2 ms 1116 KB Output is correct
43 Correct 2 ms 1116 KB Output is correct
44 Correct 2 ms 1116 KB Output is correct
45 Correct 2 ms 1116 KB Output is correct
46 Correct 2 ms 1116 KB Output is correct
47 Correct 2 ms 1116 KB Output is correct
48 Correct 2 ms 1116 KB Output is correct
49 Correct 2 ms 1116 KB Output is correct
50 Correct 2 ms 1116 KB Output is correct
51 Correct 2 ms 1116 KB Output is correct
52 Correct 2 ms 1116 KB Output is correct
53 Correct 2 ms 1116 KB Output is correct
54 Correct 9 ms 4188 KB Output is correct
55 Correct 45 ms 19804 KB Output is correct
56 Correct 45 ms 20008 KB Output is correct
57 Correct 45 ms 19800 KB Output is correct
58 Correct 43 ms 20016 KB Output is correct
59 Correct 43 ms 19800 KB Output is correct
60 Correct 41 ms 20012 KB Output is correct
61 Correct 47 ms 19804 KB Output is correct
62 Correct 54 ms 19804 KB Output is correct
63 Correct 45 ms 19800 KB Output is correct
64 Correct 49 ms 20016 KB Output is correct
65 Correct 54 ms 19800 KB Output is correct
66 Correct 56 ms 20008 KB Output is correct
67 Correct 43 ms 19804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 225 ms 65860 KB Output is correct
14 Correct 269 ms 76956 KB Output is correct
15 Correct 345 ms 89912 KB Output is correct
16 Correct 429 ms 105004 KB Output is correct
17 Correct 542 ms 122804 KB Output is correct
18 Correct 488 ms 122808 KB Output is correct
19 Correct 508 ms 122804 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 600 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 1116 KB Output is correct
59 Correct 2 ms 1116 KB Output is correct
60 Correct 2 ms 1116 KB Output is correct
61 Correct 2 ms 1116 KB Output is correct
62 Correct 2 ms 1116 KB Output is correct
63 Correct 2 ms 1116 KB Output is correct
64 Correct 2 ms 1116 KB Output is correct
65 Correct 2 ms 1116 KB Output is correct
66 Correct 2 ms 1116 KB Output is correct
67 Correct 2 ms 1116 KB Output is correct
68 Correct 2 ms 1116 KB Output is correct
69 Correct 2 ms 1116 KB Output is correct
70 Correct 2 ms 1116 KB Output is correct
71 Correct 9 ms 4188 KB Output is correct
72 Correct 45 ms 19804 KB Output is correct
73 Correct 45 ms 20008 KB Output is correct
74 Correct 45 ms 19800 KB Output is correct
75 Correct 43 ms 20016 KB Output is correct
76 Correct 43 ms 19800 KB Output is correct
77 Correct 41 ms 20012 KB Output is correct
78 Correct 47 ms 19804 KB Output is correct
79 Correct 54 ms 19804 KB Output is correct
80 Correct 45 ms 19800 KB Output is correct
81 Correct 49 ms 20016 KB Output is correct
82 Correct 54 ms 19800 KB Output is correct
83 Correct 56 ms 20008 KB Output is correct
84 Correct 43 ms 19804 KB Output is correct
85 Correct 121 ms 49372 KB Output is correct
86 Correct 332 ms 122896 KB Output is correct
87 Incorrect 315 ms 122804 KB Output isn't correct
88 Halted 0 ms 0 KB -