Submission #1110909

#TimeUsernameProblemLanguageResultExecution timeMemory
1110909luvnaBuilding Bridges (CEOI17_building)C++14
30 / 100
3035 ms2640 KiB
#include<bits/stdc++.h> #define all(v) v.begin(), v.end() #define endl "\n" #define sz(v) (int)(v).size() #define int long long using namespace std; typedef long long ll; const int N = 1e5 + 15; const ll INF = 1e18; int n; int h[N]; ll dp[N]; int w[N]; ll sum(int l, int r){ if(l > r) return 0; ll res = 0; for(int i = l; i <= r; i++) res += w[i]; return res; } void solve(){ cin >> n; for(int i = 1; i <= n; i++) cin >> h[i]; for(int i = 1; i <= n; i++) cin >> w[i]; for(int i = 2; i <= n; i++){ dp[i] = INF; for(int j = i-1; j >= 1; j--){ dp[i] = min(dp[i], 1LL*(h[i]-h[j])*(h[i]-h[j]) + sum(j+1,i-1) + dp[j]); } } cout << dp[n]; } signed main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "task" if(fopen(task".INP", "r")){ freopen(task".INP", "r", stdin); freopen(task".ANS", "w", stdout); } int t; t = 1; //cin >> t; while(t--) solve(); }

Compilation message (stderr)

building.cpp: In function 'int main()':
building.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(task".ANS", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...