Submission #1051267

#TimeUsernameProblemLanguageResultExecution timeMemory
1051267vu28082007Building Bridges (CEOI17_building)C++14
30 / 100
10 ms3804 KiB
#include <bits/stdc++.h> using namespace std; #define taskname "mvu" #define ll long long #define fi first #define se second #define pb push_back const int N = 1e5+7; ll n, h[N], w[N], f[5007], b[N]; void sub1() { for (int i = 2; i <= n; i++) { for (int j = 1; j < i; j++) { f[i]=min(f[i], f[j]+(h[i]-h[j])*(h[i]-h[j]) + b[i-1]-b[j]); } } cout << f[n]; } void mvu() { cin >> n; for (int i = 1; i <= n; i++) { f[i]=1e18; cin >> h[i]; } f[1]=0; for (int i = 1; i <= n; i++) { cin >> w[i]; if(i > 1 && i < n) b[i]=b[i-1]+w[i]; } if (n <= 5000) { sub1(); return; } ll sum1=0; sum1=b[n-1]+(h[n]-h[1])*(h[n]-h[1]); for (int i =2; i < n; i++) { sum1=min(sum1, (b[n-1]-w[i]) + (h[i]-h[1])*(h[i]-h[1]) + (h[i]-h[n])*(h[i]-h[n])); } cout << sum1; } int main() { if(fopen(taskname".inp","r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); mvu(); return 0; }

Compilation message (stderr)

building.cpp: In function 'int main()':
building.cpp:54:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     freopen(taskname".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:55:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     freopen(taskname".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...