Submission #1106364

#TimeUsernameProblemLanguageResultExecution timeMemory
1106364tradzBuilding Bridges (CEOI17_building)C++14
30 / 100
10 ms6480 KiB
#include <bits/stdc++.h> #define int long long #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define For(i,a,b) for(int i = a; i <= b; i++) #define Ford(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define ii pair<int,int> #define fi first #define se second #define all(v) v.begin(),v.end() #define RRH(v) v.resize(unique(all(v)) - v.begin()) using namespace std; const int N = 1e6+7; const int M = 1e9+7; const ll oo = 3e18; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long GetRandom(long long l, long long r) { return uniform_int_distribution<long long> (l, r)(rng); } int n, w[N], h[N]; namespace sub1 { int dp[N], pre[N]; void solve() { pre[0] = 0; For (i, 1, n) pre[i] = pre[i - 1] + w[i]; dp[1] = 0; For (i, 2, n) { dp[i] = oo; for (int j = i - 1; j >= 1; j--) { dp[i] = min(dp[j] + (h[i] - h[j]) * (h[i] - h[j]) + pre[i - 1] - pre[j], dp[i]); } //cout << i << " " << dp[i] << '\n'; } cout << dp[n] << '\n'; } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); #define TASK "" if (fopen (".inp", "r")) { freopen (".inp", "r", stdin); freopen (".out", "w", stdout); } if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } cin >> n; For (i, 1, n) cin >> h[i]; For (i, 1, n) cin >> w[i]; if (n <= 1000) { sub1 :: solve(); return 0; } cerr << "Time elapsed: " << TIME << " s.\n"; return 0; }

Compilation message (stderr)

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