답안 #554998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554998 2022-04-29T20:19:22 Z UncoolAnon Copy and Paste 3 (JOI22_copypaste3) C++14
20 / 100
1525 ms 736 KB
#include <bits/stdc++.h>
#define int long long 
using namespace std; 
const int inf=(1LL<<60); 
int n,a,b,c; string s; 
vector<int> z(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
int solve(string s){
	int n=s.size(); 
	vector<int> p=z(s),dp(n,inf); 
	vector<vector<int>> A(n+1); 
	set<int> cur;
	for(int i=1;i<n;i++){
		A[p[i]].push_back(i); 
		cur.insert(i); 
	}
	//for(int&x:p) cout << x << " " ; cout << endl << s << endl ; 
	//	return 0 ; 
	dp[0]=a; 
	for(int i=0;i<n;i++){	
		for(int x:A[i]) cur.erase(x); 
		if(i) dp[i]=min(dp[i],dp[i-1]+a); 
		int mx=1,last=i;
		while(1){
			auto it = cur.lower_bound(last+1); 
			if(it==cur.end()) break; 
			last=*it+i;
			mx++;
			dp[last]=min(dp[last],dp[i]+b+c*mx+a*(last+1-mx*(i+1))); 
		}
	}
	return dp.back(); 
}
signed main(){
	ios_base::sync_with_stdio(0); 
	cin.tie(nullptr); 
	cin>>n>>s>>a>>b>>c; 
	reverse(s.begin(),s.end()); 
	int answer=a*n; 
	for(int i=0;i<n;i++){
		string ns;
		for(int j=i;j<n;j++)ns+=s[j]; 
		answer=min(answer,solve(ns)+a*i);
	}
	cout << answer; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 727 ms 520 KB Output is correct
4 Correct 841 ms 536 KB Output is correct
5 Correct 998 ms 564 KB Output is correct
6 Correct 1212 ms 596 KB Output is correct
7 Correct 1525 ms 728 KB Output is correct
8 Correct 1522 ms 736 KB Output is correct
9 Correct 1419 ms 736 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 6 ms 340 KB Output is correct
42 Correct 6 ms 340 KB Output is correct
43 Correct 4 ms 340 KB Output is correct
44 Correct 4 ms 344 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 4 ms 340 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 4 ms 320 KB Output is correct
50 Correct 4 ms 340 KB Output is correct
51 Correct 5 ms 368 KB Output is correct
52 Incorrect 4 ms 340 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 6 ms 340 KB Output is correct
42 Correct 6 ms 340 KB Output is correct
43 Correct 4 ms 340 KB Output is correct
44 Correct 4 ms 344 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 4 ms 340 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 4 ms 320 KB Output is correct
50 Correct 4 ms 340 KB Output is correct
51 Correct 5 ms 368 KB Output is correct
52 Incorrect 4 ms 340 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 727 ms 520 KB Output is correct
14 Correct 841 ms 536 KB Output is correct
15 Correct 998 ms 564 KB Output is correct
16 Correct 1212 ms 596 KB Output is correct
17 Correct 1525 ms 728 KB Output is correct
18 Correct 1522 ms 736 KB Output is correct
19 Correct 1419 ms 736 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 316 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 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 320 KB Output is correct
50 Correct 1 ms 320 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 1 ms 324 KB Output is correct
58 Correct 6 ms 340 KB Output is correct
59 Correct 6 ms 340 KB Output is correct
60 Correct 4 ms 340 KB Output is correct
61 Correct 4 ms 344 KB Output is correct
62 Correct 3 ms 340 KB Output is correct
63 Correct 3 ms 340 KB Output is correct
64 Correct 4 ms 340 KB Output is correct
65 Correct 3 ms 340 KB Output is correct
66 Correct 4 ms 320 KB Output is correct
67 Correct 4 ms 340 KB Output is correct
68 Correct 5 ms 368 KB Output is correct
69 Incorrect 4 ms 340 KB Output isn't correct
70 Halted 0 ms 0 KB -