답안 #1106441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106441 2024-10-30T10:48:03 Z tradz Building Bridges (CEOI17_building) C++14
컴파일 오류
0 ms 0 KB
#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';
    }
}

namespace subac {
    int dp[N], pre[N];
struct Line {
    ll a, b;
    Line() {}
    Line(ll a_, ll b_) { a = a_, b = b_; }
    ll operator()(ll x) const {
        return a*x+b;
    }
};

struct seg {
    ll l, r, mid; Line val = Line(0, 1e16);
    seg() {}
    seg(ll l_, ll r_) { l = l_, r = r_, mid = (l + r) / 2; }
    seg *lc = NULL, *rc = NULL;
    void newNode() {
        if (l + 1 == r || lc != NULL) return;
        lc = new seg(l, mid); rc = new seg(mid, r);
    }
    void add(Line k) {
        if (k(mid) < val(mid)) swap(k, val);
        if (l + 1 == r) return;
        newNode();
        if (k.a > val.a) lc->add(k);
        else rc->add(k);
    }
    ll get(ll x) {
        if (l + 1 == r || lc == NULL) return val(x);
        if (x < mid) return min(val(x), lc->get(x));
        else return min(val(x), rc->get(x));
    }
};

    void solve() {
        pre[0] = 0;
        For (i, 1, n) pre[i] = pre[i - 1] + w[i];
        For (i, 1, n) dp[i] = oo;
        dp[1] = 0;
        Line bruh;
        bruh.a = -2ll * h[1];
        bruh.b = 1ll * h[1] * h[1] - pre[1];
        add(bruh);
        For (i, 2, n) {
            dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
            bruh.b = dp[i] - pre[i] + 1ll * h[i] * h[i];
            bruh.a = -2ll * h[i];
        }
        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;
    }

    subac :: solve();

    cerr << "Time elapsed: " << TIME << " s.\n";
    return 0;
}

Compilation message

building.cpp: In function 'void subac::solve()':
building.cpp:86:9: error: 'add' was not declared in this scope; did you mean 'fadd'?
   86 |         add(bruh);
      |         ^~~
      |         fadd
building.cpp:88:62: error: no matching function for call to 'get(long long int&)'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:223:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(std::pair<_Tp1, _Tp2>&)'
  223 |     get(std::pair<_Tp1, _Tp2>& __in) noexcept
      |     ^~~
/usr/include/c++/10/utility:223:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::pair<_Tp1, _Tp2>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:228:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(std::pair<_Tp1, _Tp2>&&)'
  228 |     get(std::pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^~~
/usr/include/c++/10/utility:228:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::pair<_Tp1, _Tp2>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:233:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const std::pair<_Tp1, _Tp2>&)'
  233 |     get(const std::pair<_Tp1, _Tp2>& __in) noexcept
      |     ^~~
/usr/include/c++/10/utility:233:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::pair<_Tp1, _Tp2>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:238:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(const std::pair<_Tp1, _Tp2>&&)'
  238 |     get(const std::pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^~~
/usr/include/c++/10/utility:238:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::pair<_Tp1, _Tp2>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:247:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp& std::get(std::pair<_T1, _T2>&)'
  247 |     get(pair<_Tp, _Up>& __p) noexcept
      |     ^~~
/usr/include/c++/10/utility:247:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::pair<_T1, _T2>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:252:5: note: candidate: 'template<class _Tp, class _Up> constexpr const _Tp& std::get(const std::pair<_T1, _T2>&)'
  252 |     get(const pair<_Tp, _Up>& __p) noexcept
      |     ^~~
/usr/include/c++/10/utility:252:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::pair<_T1, _T2>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:257:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp&& std::get(std::pair<_T1, _T2>&&)'
  257 |     get(pair<_Tp, _Up>&& __p) noexcept
      |     ^~~
/usr/include/c++/10/utility:257:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::pair<_T1, _T2>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:262:5: note: candidate: 'template<class _Tp, class _Up> constexpr const _Tp&& std::get(const std::pair<_T1, _T2>&&)'
  262 |     get(const pair<_Tp, _Up>&& __p) noexcept
      |     ^~~
/usr/include/c++/10/utility:262:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::pair<_T1, _T2>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:267:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp& std::get(std::pair<_Up, _Tp>&)'
  267 |     get(pair<_Up, _Tp>& __p) noexcept
      |     ^~~
/usr/include/c++/10/utility:267:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::pair<_Up, _Tp>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:272:5: note: candidate: 'template<class _Tp, class _Up> constexpr const _Tp& std::get(const std::pair<_Up, _Tp>&)'
  272 |     get(const pair<_Up, _Tp>& __p) noexcept
      |     ^~~
/usr/include/c++/10/utility:272:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::pair<_Up, _Tp>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:277:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp&& std::get(std::pair<_Up, _Tp>&&)'
  277 |     get(pair<_Up, _Tp>&& __p) noexcept
      |     ^~~
/usr/include/c++/10/utility:277:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::pair<_Up, _Tp>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from building.cpp:1:
/usr/include/c++/10/utility:282:5: note: candidate: 'template<class _Tp, class _Up> constexpr const _Tp&& std::get(const std::pair<_Up, _Tp>&&)'
  282 |     get(const pair<_Up, _Tp>&& __p) noexcept
      |     ^~~
/usr/include/c++/10/utility:282:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::pair<_Up, _Tp>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/array:334:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(std::array<_Tp, _Nm>&)'
  334 |     get(array<_Tp, _Nm>& __arr) noexcept
      |     ^~~
/usr/include/c++/10/array:334:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::array<_Tp, _Nm>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/array:343:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(std::array<_Tp, _Nm>&&)'
  343 |     get(array<_Tp, _Nm>&& __arr) noexcept
      |     ^~~
/usr/include/c++/10/array:343:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::array<_Tp, _Nm>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/array:351:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const std::array<_Tp, _Nm>&)'
  351 |     get(const array<_Tp, _Nm>& __arr) noexcept
      |     ^~~
/usr/include/c++/10/array:351:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::array<_Tp, _Nm>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/array:360:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp&& std::get(const std::array<_Tp, _Nm>&&)'
  360 |     get(const array<_Tp, _Nm>&& __arr) noexcept
      |     ^~~
/usr/include/c++/10/array:360:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::array<_Tp, _Nm>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/tuple:1294:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(std::tuple<_Elements ...>&)'
 1294 |     get(tuple<_Elements...>& __t) noexcept
      |     ^~~
/usr/include/c++/10/tuple:1294:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::tuple<_Elements ...>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/tuple:1300:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(const std::tuple<_Elements ...>&)'
 1300 |     get(const tuple<_Elements...>& __t) noexcept
      |     ^~~
/usr/include/c++/10/tuple:1300:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::tuple<_Elements ...>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/tuple:1306:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(std::tuple<_Elements ...>&&)'
 1306 |     get(tuple<_Elements...>&& __t) noexcept
      |     ^~~
/usr/include/c++/10/tuple:1306:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::tuple<_Elements ...>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/tuple:1315:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(const std::tuple<_Elements ...>&&)'
 1315 |     get(const tuple<_Elements...>&& __t) noexcept
      |     ^~~
/usr/include/c++/10/tuple:1315:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::tuple<_Elements ...>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/tuple:1338:5: note: candidate: 'template<class _Tp, class ... _Types> constexpr _Tp& std::get(std::tuple<_Elements ...>&)'
 1338 |     get(tuple<_Types...>& __t) noexcept
      |     ^~~
/usr/include/c++/10/tuple:1338:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::tuple<_Elements ...>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/tuple:1344:5: note: candidate: 'template<class _Tp, class ... _Types> constexpr _Tp&& std::get(std::tuple<_Elements ...>&&)'
 1344 |     get(tuple<_Types...>&& __t) noexcept
      |     ^~~
/usr/include/c++/10/tuple:1344:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'std::tuple<_Elements ...>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/tuple:1350:5: note: candidate: 'template<class _Tp, class ... _Types> constexpr const _Tp& std::get(const std::tuple<_Elements ...>&)'
 1350 |     get(const tuple<_Types...>& __t) noexcept
      |     ^~~
/usr/include/c++/10/tuple:1350:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::tuple<_Elements ...>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
In file included from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from building.cpp:1:
/usr/include/c++/10/tuple:1357:5: note: candidate: 'template<class _Tp, class ... _Types> constexpr const _Tp&& std::get(const std::tuple<_Elements ...>&&)'
 1357 |     get(const tuple<_Types...>&& __t) noexcept
      |     ^~~
/usr/include/c++/10/tuple:1357:5: note:   template argument deduction/substitution failed:
building.cpp:88:62: note:   mismatched types 'const std::tuple<_Elements ...>' and 'long long int'
   88 |             dp[i] = pre[i - 1] + 1ll * h[i] * h[i] + get(h[i]);
      |                                                              ^
building.cpp: In function 'int32_t main()':
building.cpp:101:17: warning: ignoring return value of 'FILE* freopen(const c