Submission #203381

#TimeUsernameProblemLanguageResultExecution timeMemory
203381wendy_virgoBuilding Bridges (CEOI17_building)C++14
30 / 100
3079 ms2588 KiB
#include <bits/stdc++.h> using namespace std; #define taskname "CEOI17_building" #define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define foreach(i, x) for (auto &i : x) #define ms(x, n) memset(x, n, sizeof(x)) #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define uni(x) (x).erase(unique(all(x)), (x).end()) #define fi first #define se second #define pb push_back #define pf push_front template<typename TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << " = " << h << "\n"; } template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while (*sdbg != ',') cerr << *sdbg++; cerr << " = " << h << ","; _dbg(sdbg + 1, t...); } #define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define chkpt cerr << "--- Checkpoint here ---\n"; const int N=1e5+5; const int64_t LINF=1e18; int n,h[N],w[N]; int64_t f[N]; void Sub1() { int64_t sumW=0; forinc(i,1,n) { sumW+=w[i]; } f[1]=-w[1]; forinc(i,2,n) { f[i]=LINF; forinc(j,1,i-1) { f[i]=min(f[i],f[j]+(int64_t)(h[i]-h[j])*(h[i]-h[j])-w[i]); } } cout<<f[n]+sumW; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE // freopen(taskname".INP","r",stdin); #endif // ONLINE_JUDGE cin>>n; forinc(i,1,n) { cin>>h[i]; } forinc(i,1,n) { cin>>w[i]; } Sub1(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...