100082024-03-23 23:20:15111Jancsi és Juliska kitalálós játékacpp17Time limit exceeded 100/1001.088s7060 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int N,F[300],C[300][300],A[300][300];

int solve(int l,int r){
	if(l>=r){
		return 0;
	}
	if(A[l][r]!=-1){
		return A[l][r];
	}
	int a=INT_MAX;
	for(int i=l;i<=r;i++){
		for(int j=i;j<=r;j++){
			if(i==l&&j==r){
				continue;
			}
			int xxx=solve(j+1,r);
			int xx=max({solve(l,i-1),solve(i,j)});
			int x=C[i][j]+max(xx,xxx);
			if(x<a){
				a=x;
			}
			if(xxx<=xx)break;
		}
	}
	A[l][r]=a;
	return a;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>F[i];
	}
	for(int i=0;i<N;i++){
		C[i][i]=F[i];
		for(int j=i+1;j<N;j++){
			C[i][j]=max(C[i][j-1],F[j]);
		}
	}
	for(int i=0;i<N;i++){
		for(int j=i;j<N;j++){
			A[i][j]=-1;
		}
	}
	cout<<solve(0,N-1)<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms1804 KiB
2Time limit exceeded0/01.088s4908 KiB
3Accepted4/43ms2596 KiB
4Accepted5/53ms2708 KiB
5Accepted5/53ms2976 KiB
6Accepted5/53ms2980 KiB
7Accepted5/512ms3944 KiB
8Accepted5/510ms3992 KiB
9Accepted5/532ms4484 KiB
10Accepted5/541ms4920 KiB
11Accepted5/532ms4880 KiB
12Accepted5/572ms5352 KiB
13Accepted5/5128ms5536 KiB
14Accepted5/5164ms5636 KiB
15Accepted5/5354ms6168 KiB
16Accepted5/5598ms6280 KiB
17Accepted5/5268ms6332 KiB
18Accepted5/5293ms6356 KiB
19Accepted5/5830ms6664 KiB
20Accepted5/5365ms6788 KiB
21Accepted5/5936ms6784 KiB
22Accepted6/6735ms7060 KiB