Submission #319589

# Submission time Handle Problem Language Result Execution time Memory
319589 2020-11-05T15:51:52 Z parsabahrami Building Bridges (CEOI17_building) C++17
0 / 100
26 ms 5996 KB
//! The Leader Of Retards Bemola
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;
 
#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
        if (b & 1)
            ans = ans * a % md;
    return ans % md;
}
const ll MAXN = 1e5 + 10;
const ll INF  = 1e18;
const ll MOD  = 1e9 + 7;
ll dp[MAXN], H[MAXN], W[MAXN], ps[MAXN], n;
pll M[MAXN];

int main() {
	scanf("%lld", &n);
	for (ll i = 1; i <= n; i++) {
		scanf("%lld", &H[i]);
	}
	for (ll i = 1; i <= n; i++) {
		scanf("%lld", &W[i]);
	}
	fill(dp, dp + MAXN, INF);
	partial_sum(W, W + MAXN, ps);
	dp[1] = 0; M[1] = {1 - ps[1] + H[1] * H[1], H[1]};
	for (ll i = 2; i <= n; i++) {
		dp[i] = ps[i - 1] + H[i] * H[i] + M[i - 1].F - 2 * H[i] * M[i - 1].S;
		M[i] = min(M[i - 1], {dp[i] - ps[i] + H[i] * H[i], H[i]});
	}
	printf("%lld\n", dp[n]);
    return 0;
}

Compilation message

building.cpp: In function 'int main()':
building.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  scanf("%lld", &n);
      |  ~~~~~^~~~~~~~~~~~
building.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |   scanf("%lld", &H[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
building.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |   scanf("%lld", &W[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 5996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1900 KB Output isn't correct
2 Halted 0 ms 0 KB -