제출 #1133801

#제출 시각아이디문제언어결과실행 시간메모리
1133801t9unkubj스카이라인 (IZhO11_skyline)C++20
0 / 100
1 ms328 KiB
#ifdef t9unkubj #include"debug.cpp" //#include"template_no_debug.h" #else #define dbg(...) 199958 #endif #undef _GLIBCXX_DEBUG #pragma GCC optimize("O3") using namespace std; #include<bits/stdc++.h> using ll=long long; using ull=unsigned long long; template<class T>using vc=vector<T>; template<class T>using vvc=vc<vc<T>>; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=(n);i>=(m);i--) #define drep(i,n) for(ll i=((n)-1);i>=0;i--) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() template<class T,class F> bool chmin(T &x, F y){ if(x>y){ x=y; return true; } return false; } template<class T, class F> bool chmax(T &x, F y){ if(x<y){ x=y; return true; } return false; } double pass_time=0; void solve(){ int n; cin>>n; vc<int>h(n); rep(i,n)cin>>h[i]; if(n==1){ cout<<h[0]*3<<"\n"; return; } if(n==2){ cout<<min(h[0],h[1])*5+((max(h[0],h[1])-min(h[0],h[1]))*3)<<"\n"; return; } ll ans=2e18; rep(i,min({h[0],h[1],h[2]})+1){ rep(j,min({h[0],h[1]})+1){ auto nh=h; nh[0]-=i; nh[1]-=i; nh[2]-=i; nh[0]-=j; nh[1]-=j; if(nh[0]<0||nh[1]<0||nh[2]<0){ continue; } int cost=i*7+j*5+nh[0]*3; for(int k=1;k+1<n;k++){ if(k+2<n){ int use3=min({nh[k],nh[k+1],nh[k+2]}); cost+=use3*7; rep(j,3)nh[k+j]-=use3; } int use2=min({nh[k],nh[k+1]}); cost+=use2*5; rep(j,3)nh[k+j]-=use2; } chmin(ans,cost+accumulate(all(nh),0)*3); } } cout<<ans<<"\n"; } signed main(){ cin.tie(0)->sync_with_stdio(0); pass_time=clock(); int t=1; //cin>>t; while(t--)solve(); pass_time=clock()-pass_time; dbg(pass_time/CLOCKS_PER_SEC); }
#Verdict Execution timeMemoryGrader output
Fetching results...