Submission #476168

# Submission time Handle Problem Language Result Execution time Memory
476168 2021-09-25T07:27:30 Z Neos Building Bridges (CEOI17_building) C++14
0 / 100
1 ms 1740 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
 
#define task "test"
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i, l, r) for( ll i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( ll i = (r) ; i >= (l) ; i-- )
#define sz(x) (int)x.size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define numBit(x) __builtin_popcount(x)
#define lb lower_bound
#define ub upper_bound
#define ar array
#define endl '\n'
 
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
 
const int N = 2e5 + 7;
const ll inf = 0x3f3f3f3f;

int n;
ll h[N], w[N], dp[N];

ll sum(int i, int j) {
  return w[j] - w[i - 1];
}

ll sqr(int x) {
  return 1LL * x * x;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen(task".inp", "r", stdin);
  freopen(task".out", "w", stdout);
#endif
  // fastIO;

  scanf("%d", &n);
  forw(i, 1, n + 1) scanf("%lld", &h[i]);
  forw(i, 1, n + 1) scanf("%lld", &w[i]), w[i] += w[i - 1];

  memset(dp, 0x3f, sizeof dp);
  if (n <= 1000) {
    dp[1] = 0;
    forw(i, 1, n + 1) forb(j, i - 1, 1) 
      dp[i] = min(dp[i], dp[j] + sqr(h[i] - h[j]) + sum(j + 1, i - 1));
    cout << dp[n] << endl;
  }
  else {
    
  }
}

/*
  Subtask 1: dp[i] = max(dp[j] + (hi - hj) ^ 2 + sum(w[i + 1]...w[j])
  Subtask 2: Chọn 2 cây cầu sao cho h[1] + sum(2, i - 1) + h[i] + sum(i + 1, j - 1) + h[j] + sum(j + 1, n - 1) + h[n] 

*/

Compilation message

building.cpp: In function 'int main()':
building.cpp:49:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:50:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
building.cpp:55:26: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   forw(i, 1, n + 1) scanf("%lld", &h[i]);
      |                     ~~~~~^~~~~~~~~~~~~~~
building.cpp:56:26: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |   forw(i, 1, n + 1) scanf("%lld", &w[i]), w[i] += w[i - 1];
      |                     ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1740 KB Output isn't correct
2 Halted 0 ms 0 KB -