Submission #476169

#TimeUsernameProblemLanguageResultExecution timeMemory
476169NeosBuilding Bridges (CEOI17_building)C++14
30 / 100
3084 ms4404 KiB
#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() { // 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); 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; } /* 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 (stderr)

building.cpp: In function 'int main()':
building.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
building.cpp:51:26: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   forw(i, 1, n + 1) scanf("%lld", &h[i]);
      |                     ~~~~~^~~~~~~~~~~~~~~
building.cpp:52:26: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   forw(i, 1, n + 1) scanf("%lld", &w[i]), w[i] += w[i - 1];
      |                     ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...