답안 #548742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548742 2022-04-14T11:18:59 Z luka1234 Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
3000 ms 20692 KB
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
ll n,A,B,C;
string s="#";
string s1;
ll xar[2501];
ll hs[2501];
ll num[501];
ll pir[501];
ll dp[2501][2501];
ll p=1000000007;
void makehash(string s){
	xar[0]=1;
	ll cd;
	for(int k=1;k<=n;k++){
		xar[k]=xar[k-1]*31;
		xar[k]%=p;
	}
	hs[0]=0;
	for(int k=1;k<=n;k++){
		hs[k]=hs[k-1]*31;
		hs[k]%=p;
		cd=s[k]-'a';
		hs[k]+=cd;
		hs[k]%=p;
	}
}
ll gethash(int l,int r){
	ll ans;
	ll raodenoba=r-l+1;
	ll r1=hs[r];
	ll r2=hs[l-1]*xar[raodenoba];
	r1%=p;
	r2%=p;
	ans=r2-r1;
	ans+=p;
	ans%=p;
	return ans;
}
int main(){
	/*ios_base::sync_with_stdio(0);
	cin.tie(0);*/
	cin>>n;
	cin>>s1;
	s+=s1;
	cin>>A>>B>>C;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			dp[i][j]=1e18;
		}
	}
	ll len=0;
	ll newlen=0;
	ll ric1=0,ric2=0;
	makehash(s);
	for(int r=1;r<=n;r++){
		for(int i=0;i<=r;i++){
			num[i]=0;
			pir[i]=1e18;
		}
		for(int l=r;l>=1;l--){
			dp[l][r]=min(dp[l][r],dp[l][r-1]+A);
			for(int i=l;i<=r;i++){
				len=i-l+1;
				ric1=gethash(l,i);
				ric2=gethash(r-len+1,r);
				if(ric1==ric2&&i<pir[len]){
				    pir[len]=l;
					num[len]++;	
				}
				newlen=(C-len*A)*num[len]+(r-l+1)*A+dp[r-len+1][r]+B;
				dp[l][r]=min(dp[l][r],newlen);
			}
		}
	}
	cout<<dp[1][n];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 3068 ms 20692 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 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 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 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 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 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 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 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 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 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 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 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 340 KB Output is correct
40 Correct 4 ms 596 KB Output is correct
41 Correct 45 ms 1236 KB Output is correct
42 Correct 49 ms 1268 KB Output is correct
43 Correct 47 ms 1268 KB Output is correct
44 Correct 51 ms 1264 KB Output is correct
45 Correct 50 ms 1236 KB Output is correct
46 Correct 47 ms 1236 KB Output is correct
47 Correct 48 ms 1268 KB Output is correct
48 Correct 44 ms 1236 KB Output is correct
49 Correct 48 ms 1276 KB Output is correct
50 Correct 47 ms 1236 KB Output is correct
51 Correct 52 ms 1268 KB Output is correct
52 Correct 49 ms 1292 KB Output is correct
53 Correct 44 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 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 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 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 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 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 340 KB Output is correct
40 Correct 4 ms 596 KB Output is correct
41 Correct 45 ms 1236 KB Output is correct
42 Correct 49 ms 1268 KB Output is correct
43 Correct 47 ms 1268 KB Output is correct
44 Correct 51 ms 1264 KB Output is correct
45 Correct 50 ms 1236 KB Output is correct
46 Correct 47 ms 1236 KB Output is correct
47 Correct 48 ms 1268 KB Output is correct
48 Correct 44 ms 1236 KB Output is correct
49 Correct 48 ms 1276 KB Output is correct
50 Correct 47 ms 1236 KB Output is correct
51 Correct 52 ms 1268 KB Output is correct
52 Correct 49 ms 1292 KB Output is correct
53 Correct 44 ms 1236 KB Output is correct
54 Correct 499 ms 2900 KB Output is correct
55 Execution timed out 3087 ms 8148 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Execution timed out 3068 ms 20692 KB Time limit exceeded
14 Halted 0 ms 0 KB -