답안 #861012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861012 2023-10-15T06:41:16 Z willychan Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
2480 ms 1124 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
#define pt pair<pair<int,int>,pair<int,int> >
#define xl first.first
#define xr first.second
#define yl second.first
#define yr second.second

const int N = 205;
ll dp[N][N];
string s;
int a,b,c;
int howmany[N][N];
const int MOD = 1e9+7;
int hsh[N];
int ppow[N];
int get(int l,int r){
	ll ans = hsh[r];
	ans = (ans-(1LL*hsh[l-1]*ppow[r-l+1])%MOD)%MOD;
	if(ans<0) ans+=MOD;
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;cin>>n;
	cin>>s;
	cin>>a>>b>>c;	
	ppow[0]=1;
	for(int i=1;i<=n;i++){
		hsh[i] = (1LL*hsh[i-1]*31)%MOD;
		hsh[i]+=(s[i-1]-'a');
		hsh[i]%=MOD;
		ppow[i] = (31LL*ppow[i-1])%MOD;
	}
	for(int i=0;i<=n+1;i++){
		for(int j=i;j<=n+1;j++) dp[i][j]=1LL*(j-i+1)*a+b;
	}
	for(int l=0;l<n;l++){
		for(int i=1;i+l<=n;i++){
			for(int l2=0;l2<n;l2++){
				for(int j=1;j+l2<=n;j++){
					if(l2<l){howmany[j][j+l2]=0;continue;}
					if(l2==l){
						howmany[j][j+l2] = (get(i,i+l)==get(j,j+l));
					}else{
						if(get(i,i+l)==get(j,j+l)) howmany[j][j+l2] = 1+howmany[j+l+1][j+l2];
						else howmany[j][j+l2] = howmany[j+1][j+l2];
						int k = (l2+1)-(1LL*howmany[j][j+l2]*(l+1));
						dp[j][j+l2] = min(dp[j][j+l2],dp[i][i+l]+(1LL*howmany[j][j+l2]*c)+(1LL*a*k)+b);
					}
				}
			}
			//cout<<dp[i][i+l]<<" ";
		}
		//cout<<"\n";
	}
	cout<<dp[1][n]-b<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 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 1 ms 344 KB Output is correct
9 Correct 1 ms 600 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 Runtime error 1 ms 1116 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 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 1 ms 344 KB Output is correct
9 Correct 1 ms 600 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 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 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 548 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 344 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 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 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 1 ms 344 KB Output is correct
9 Correct 1 ms 600 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 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 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 548 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 344 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 2 ms 348 KB Output is correct
40 Correct 82 ms 648 KB Output is correct
41 Correct 2480 ms 928 KB Output is correct
42 Correct 2473 ms 928 KB Output is correct
43 Correct 2422 ms 932 KB Output is correct
44 Correct 2443 ms 928 KB Output is correct
45 Correct 2428 ms 948 KB Output is correct
46 Correct 2439 ms 1108 KB Output is correct
47 Correct 2432 ms 928 KB Output is correct
48 Correct 2474 ms 932 KB Output is correct
49 Correct 2435 ms 948 KB Output is correct
50 Correct 2457 ms 1112 KB Output is correct
51 Correct 2430 ms 936 KB Output is correct
52 Correct 2468 ms 936 KB Output is correct
53 Correct 2439 ms 932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 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 1 ms 344 KB Output is correct
9 Correct 1 ms 600 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 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 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 548 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 344 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 2 ms 348 KB Output is correct
40 Correct 82 ms 648 KB Output is correct
41 Correct 2480 ms 928 KB Output is correct
42 Correct 2473 ms 928 KB Output is correct
43 Correct 2422 ms 932 KB Output is correct
44 Correct 2443 ms 928 KB Output is correct
45 Correct 2428 ms 948 KB Output is correct
46 Correct 2439 ms 1108 KB Output is correct
47 Correct 2432 ms 928 KB Output is correct
48 Correct 2474 ms 932 KB Output is correct
49 Correct 2435 ms 948 KB Output is correct
50 Correct 2457 ms 1112 KB Output is correct
51 Correct 2430 ms 936 KB Output is correct
52 Correct 2468 ms 936 KB Output is correct
53 Correct 2439 ms 932 KB Output is correct
54 Runtime error 1 ms 1124 KB Execution killed with signal 11
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 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 1 ms 344 KB Output is correct
9 Correct 1 ms 600 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 Runtime error 1 ms 1116 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -