# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
36306 |
2017-12-07T10:51:56 Z |
Kerim |
Skyline (IZhO11_skyline) |
C++14 |
|
393 ms |
54884 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)
return x*3;
int &ret=dp[x][y][pos];
if(~ret)
return ret;ret=INF;
if(pos+2<=n){
if(x){
umin(ret,rec(x-1,y,pos)+3);
if(y)
umin(ret,rec(x-1,y-1,pos)+5);
}
if(y>=x and arr[pos+2]>=x)
umin(ret,rec(y-x,arr[pos+2]-x,pos+1)+x*7);
}
else{
if(!x)
ret=rec(y,0,n);
else{
umin(ret,rec(x-1,y,pos)+3);
if(y)
umin(ret,rec(x-1,y-1,pos)+5);
}
}
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;
}
memset(dp,-1,sizeof dp);
printf("%d\n",rec(arr[1],arr[2],1));
return 0;
}
Compilation message
skyline.cpp: In function 'int main()':
skyline.cpp:53:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
skyline.cpp:55:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",arr+i);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
50312 KB |
Output is correct |
2 |
Correct |
0 ms |
50312 KB |
Output is correct |
3 |
Correct |
3 ms |
50312 KB |
Output is correct |
4 |
Correct |
0 ms |
50312 KB |
Output is correct |
5 |
Correct |
3 ms |
50312 KB |
Output is correct |
6 |
Correct |
3 ms |
50312 KB |
Output is correct |
7 |
Correct |
3 ms |
50312 KB |
Output is correct |
8 |
Correct |
3 ms |
50312 KB |
Output is correct |
9 |
Correct |
13 ms |
50312 KB |
Output is correct |
10 |
Correct |
9 ms |
50368 KB |
Output is correct |
11 |
Correct |
53 ms |
51256 KB |
Output is correct |
12 |
Correct |
16 ms |
50444 KB |
Output is correct |
13 |
Correct |
53 ms |
51380 KB |
Output is correct |
14 |
Correct |
93 ms |
51864 KB |
Output is correct |
15 |
Correct |
253 ms |
53832 KB |
Output is correct |
16 |
Correct |
269 ms |
53568 KB |
Output is correct |
17 |
Correct |
386 ms |
54884 KB |
Output is correct |
18 |
Correct |
373 ms |
54744 KB |
Output is correct |
19 |
Correct |
353 ms |
54480 KB |
Output is correct |
20 |
Correct |
393 ms |
54860 KB |
Output is correct |