답안 #890230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890230 2023-12-20T17:58:04 Z amirhoseinfar1385 Copy and Paste 3 (JOI22_copypaste3) C++17
0 / 100
1 ms 604 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=100+10;
int lcp[maxn][maxn],nxt[maxn][maxn],n;
long long dp[maxn][maxn],a,b,c,inf=1e15;
string s;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>s;
	cin>>a>>b>>c;
	for(int i=n-1;i>=0;i--){
		for(int j=i+1;j<n;j++){
			if(s[i]==s[j]){
				lcp[i][j]=lcp[i+1][j+1]+1;
			}
		}
	}
	for(int i=0;i<maxn;i++){
		for(int j=0;j<maxn;j++){
			nxt[i][j]=n+3;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			nxt[i][min(lcp[i][j],j-i)]=j;
		}
		for(int j=n;j>=0;j--){
			nxt[i][j]=min(nxt[i][j],nxt[i][j+1]);
		}
	}
	for(int i=0;i<maxn;i++){
		for(int j=0;j<maxn;j++){
			dp[i][j]=inf;
		}
	}
	for(int i=n-1;i>=0;i--){
		dp[i][i]=a;
		for(int j=i+1;j<n;j++){
			dp[i][j]=min(dp[i][j],min(dp[i+1][j],dp[i][j-1])+a);
		}
		for(int j=1;j<n;j++){
			int ted=2;
			long long z=dp[i][j+i-1];
			for(int h=nxt[i][j];h!=n+3;h=nxt[h][j]){
			//	cout<<i<<" "<<h<<" "<<j<<" "<<ted<<" "<<z<<" "<<endl;
				dp[i][h+j-1]=min(dp[i][h+j-1],z+ted*c+b+a*(h+j-i-(ted*j)));
				ted++;
			}
		}
	}
	cout<<dp[0][n-1]<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Runtime error 1 ms 460 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -