답안 #870451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870451 2023-11-08T02:06:26 Z cpptowin Building Bridges (CEOI17_building) C++17
0 / 100
18 ms 25692 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf 1000000000
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1 << j))
#define onbit(i, j) (i | (1 << j))
#define vi vector<int>
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
// #define int long long
#define inf 1000000000
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1 << j))
#define onbit(i, j) (i | (1 << j))
#define vi vector<int>
using namespace std;
struct CHT
{
pii line[maxn];
int p[maxn];
int s[maxn];
int top;
int eval(pii a, int x)
{
    return a.fi * x + a.se;
}
bool bad(pii a, pii b, pii c)
{
    return (double)(b.se - a.se) / (a.fi - b.fi) <= (double)(c.se - a.se) / (a.fi - c.fi);
}
int get(int coor)
{
    int l = 0, r = top - 1, ans = eval(line[l], coor);
    while (l < r)
    {
        int mid = (l + r) >> 1;
        int x = eval(line[mid], coor);
        int y = eval(line[mid + 1], coor);
        if (x > y)
            l = mid + 1;
        else
            r = mid;
        ans = min(ans, min(x, y));
    }
    return ans;
}
void add(pii newline)
{
    int l = 1, r = top - 1, k = top;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (bad(line[mid - 1], line[mid], newline))
            k = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    line[k] = newline;
    top = k + 1;
}
} cht;
int n;
int h[maxn];
int w[maxn];
int pre[maxn];
int dp[maxn];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    fo(i, 1, n) cin >> h[i];
    fo(i, 1, n)
    {
        cin >> w[i];
        pre[i] = pre[i - 1] + w[i];
    }
    // fo(i,1,n) cout << pre[i] << ' ';en;
    cht.add({-2 * h[1], h[1] * h[1] + w[1]});
    fo(i, 2, n)
    {
        dp[i] = cht.get(h[i]) + pre[i - 1] + h[i] * h[i];
        cht.add({-2 * h[i] ,h[i] * h[i] - pre[i] + dp[i]});
    }
    // fo(i,1,n) cout << dp[i] << ' ' ;en;
    cout << dp[n];
}

Compilation message

building.cpp:109:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  109 | main()
      | ^~~~
building.cpp: In function 'int main()':
building.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 20828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 25692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 20828 KB Output isn't correct
2 Halted 0 ms 0 KB -