Submission #956870

# Submission time Handle Problem Language Result Execution time Memory
956870 2024-04-02T15:11:11 Z Trisanu_Das Building Bridges (CEOI17_building) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
struct Line {
	mutable ll k, m, p;
	bool operator<(const Line& o) const { return k < o.k; }
	bool operator<(ll x) const { return p < x; }
};
 
struct LineContainer : multiset<Line, less<>> {
	// (for doubles, use inf = 1/.0, div(a,b) = a/b)
	static const ll inf = LLONG_MAX;
	ll div(ll a, ll b) { // floored division
		return a / b - ((a ^ b) < 0 && a % b); }
	bool isect(iterator x, iterator y) {
		if (y == end()) return x->p = inf, 0;
		if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
		else x->p = div(y->m - x->m, x->k - y->k);
		return x->p >= y->p;
	}
	void add(ll k, ll m) {
		auto z = insert({k, m, 0}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}
	ll query(ll x) {
		assert(!empty());
		auto l = *lower_bound(x);
		return l.k * x + l.m;
	}
};
 
int main(){
  int n; cin >> n;
  int h[n + 2], w[n + 2], dp[n + 1];
  for(int i = 1; i <= n; i++) cin >> h[i];
  for(int i = 1; i <= n; i++) cin >> w[i];
  LineContainer hull;
  dp[1] = -w[i];
  for(int i = 2; i <= n; i++){
    hull.add(2 * h[i - 1], h[i - 1] * h[i - 1] + dp[i - 1]);
    dp[i] = hull.query(h[i]) + h[i] * h[i] - w[i];
  }
  cout << dp[n] + accumulate(w + 1, w + n + 1) << '\n';
}

Compilation message

building.cpp: In function 'int main()':
building.cpp:42:14: error: 'i' was not declared in this scope
   42 |   dp[1] = -w[i];
      |              ^
building.cpp:47:46: error: no matching function for call to 'accumulate(int*, int*)'
   47 |   cout << dp[n] + accumulate(w + 1, w + n + 1) << '\n';
      |                                              ^
In file included from /usr/include/c++/10/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
                 from building.cpp:1:
/usr/include/c++/10/bits/stl_numeric.h:134:5: note: candidate: 'template<class _InputIterator, class _Tp> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp)'
  134 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
      |     ^~~~~~~~~~
/usr/include/c++/10/bits/stl_numeric.h:134:5: note:   template argument deduction/substitution failed:
building.cpp:47:46: note:   candidate expects 3 arguments, 2 provided
   47 |   cout << dp[n] + accumulate(w + 1, w + n + 1) << '\n';
      |                                              ^
In file included from /usr/include/c++/10/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
                 from building.cpp:1:
/usr/include/c++/10/bits/stl_numeric.h:161:5: note: candidate: 'template<class _InputIterator, class _Tp, class _BinaryOperation> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation)'
  161 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
      |     ^~~~~~~~~~
/usr/include/c++/10/bits/stl_numeric.h:161:5: note:   template argument deduction/substitution failed:
building.cpp:47:46: note:   candidate expects 4 arguments, 2 provided
   47 |   cout << dp[n] + accumulate(w + 1, w + n + 1) << '\n';
      |                                              ^