답안 #36305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36305 2017-12-07T10:36:47 Z Kerim 스카이라인 (IZhO11_skyline) C++14
0 / 100
2000 ms 50316 KB
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx") 
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int K=202;
const int N=303;
int dp[K][K][N],n,arr[N];
int rec(int x,int y,int pos){
	if(pos>n){
		if(x or y)
			return INF;
		return 0;
	}
	if(x>arr[pos] or x>y)
		return INF;
	int &ret=dp[x][y][pos];
	if(~ret)
		return ret;ret=INF;
	for(int i=0;i+x<=min(y,arr[pos]);i++)
		for(int j=0;j+x+i<=arr[pos];j++)
			umin(ret,rec(y-(x+i),arr[pos]-(j+x+i),pos+1)+j*3+i*5+x*7);
	return ret;		
}
int main(){
    //~ freopen("file.in", "r", stdin);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	if(n==1){
		printf("%d\n",arr[1]*3);
		return 0;
	}	
	if(n==2){
		printf("%d\n",min(arr[1],arr[2])*5+(max(arr[1],arr[2])-min(arr[1],arr[2]))*3);
		return 0;
	}
	int ans=INF;
	memset(dp,-1,sizeof dp);
	for(int i=0;i<=min(arr[1],arr[2]);i++)
		for(int j=0;j<=arr[1];j++)
			for(int k=0;k<=arr[2];k++){
				if(arr[1]<i+j or arr[2]<i+k)
					continue;
				umin(ans,rec(arr[1]-(i+j),arr[2]-(i+k),3)+i*5+j*3+k*3);	
			}
	printf("%d\n",ans);		
	return 0;
}

Compilation message

skyline.cpp: In function 'int main()':
skyline.cpp:43:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
skyline.cpp:45:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",arr+i);
                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 50316 KB Output is correct
2 Correct 0 ms 50316 KB Output is correct
3 Correct 3 ms 50316 KB Output is correct
4 Correct 6 ms 50316 KB Output is correct
5 Correct 6 ms 50316 KB Output is correct
6 Correct 0 ms 50316 KB Output is correct
7 Correct 6 ms 50316 KB Output is correct
8 Correct 83 ms 50316 KB Output is correct
9 Correct 303 ms 50316 KB Output is correct
10 Correct 1549 ms 50316 KB Output is correct
11 Execution timed out 2000 ms 50316 KB Execution timed out
12 Halted 0 ms 0 KB -